本文整理汇总了C#中Int2类的典型用法代码示例。如果您正苦于以下问题:C# Int2类的具体用法?C# Int2怎么用?C# Int2使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Int2类属于命名空间,在下文中一共展示了Int2类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: UploadCharacterBitmap
/// <summary>
/// Upload a character's bitmap into the current cache.
/// </summary>
/// <param name="character">The character specifications corresponding to the bitmap</param>
public void UploadCharacterBitmap(CharacterSpecification character)
{
if(character.Bitmap == null)
throw new ArgumentNullException("character");
if(character.IsBitmapUploaded)
throw new InvalidOperationException("The character '"+character.Character+"' upload has been requested while its current glyph is valid.");
var targetSize = new Int2(character.Bitmap.Width, character.Bitmap.Rows);
if (!packer.Insert(targetSize.X, targetSize.Y, ref character.Glyph.Subrect))
{
// not enough space to place the new character -> remove less used characters and try again
RemoveLessUsedCharacters();
if (!packer.Insert(targetSize.X, targetSize.Y, ref character.Glyph.Subrect))
{
// memory is too fragmented in order to place the new character -> clear all the characters and restart.
ClearCache();
if (!packer.Insert(targetSize.X, targetSize.Y, ref character.Glyph.Subrect))
throw new InvalidOperationException("The rendered character is too big for the cache texture");
}
}
// updload the bitmap on the texture (if the size in the bitmap is not null)
if (character.Bitmap.Rows != 0 && character.Bitmap.Width != 0)
{
var dataBox = new DataBox(character.Bitmap.Buffer, character.Bitmap.Pitch, character.Bitmap.Pitch * character.Bitmap.Rows);
var region = new ResourceRegion(character.Glyph.Subrect.Left, character.Glyph.Subrect.Top, 0, character.Glyph.Subrect.Right, character.Glyph.Subrect.Bottom, 1);
system.GraphicsDevice.UpdateSubresource(cacheTextures[0], 0, dataBox, region);
}
// update the glyph data
character.IsBitmapUploaded = true;
character.Glyph.BitmapIndex = 0;
}
开发者ID:Powerino73,项目名称:paradox,代码行数:37,代码来源:FontCacheManager.cs
示例2: PlaneProceduralModel
/// <summary>
/// Initializes a new instance of geometric descriptor for a plane.
/// </summary>
public PlaneProceduralModel()
{
Normal = NormalDirection.UpY;
Size = new Vector2(1.0f);
Tessellation = new Int2(1);
UVScales = new Vector2(1);
}
开发者ID:ItayGal2,项目名称:paradox,代码行数:10,代码来源:PlaneProceduralModel.cs
示例3: getPath
public static Int2[] getPath(Int2 current, Int2 final, GridSystem grid)
{
int width = grid.gridSizeX;
int height = grid.gridSizeZ;
if (width <= current._x || width <= final._x) {
return null;
}
if (height <= current._z || height <= final._z) {
return null;
}
if (grid[current._x, current._z] == null || grid[final._x,final._z] == null)
{
return null;
}
int[,] distanceGrid = new int[width, height];
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
distanceGrid[i,j] = -1;
}
}
distanceGrid [current._x, current._z] = 0;
Int2[] path = DFS (current, final, grid, distanceGrid);
Debug.Log ("Path");
for (int i = 0; i < path.Length; i++) {
Debug.Log (path[i]);
}
return path;
}
开发者ID:MangoSister,项目名称:Space-Escape,代码行数:29,代码来源:PathFinder.cs
示例4: RemoveBlock
public bool RemoveBlock(int x, int y)
{
Int2 coord = new Int2(x, y);
if (blocks.ContainsKey(coord))
{
blocks.Remove(coord);
return true;
}
return false;
}
开发者ID:roenyroeny,项目名称:spacesheep,代码行数:10,代码来源:ShipMap.cs
示例5: PackingAttributes
/// <summary>
/// Creates a default instance of packing attributes.
/// </summary>
public PackingAttributes()
{
Enabled = true;
PackingAlgorithm = TexturePackingMethod.Best;
AllowMultipacking = true;
AllowRotations = true;
AtlasMaximumSize = new Int2(2048);
BorderSize = 2;
}
开发者ID:Julyuary,项目名称:paradox,代码行数:15,代码来源:PackingAttributes.cs
示例6: DrawCore
protected override void DrawCore(RenderContext context)
{
var output = PrefilteredRadiance;
if(output == null || (output.Dimension != TextureDimension.Texture2D && output.Dimension != TextureDimension.TextureCube) || output.ArraySize != 6)
throw new NotSupportedException("Only array of 2D textures are currently supported as output");
var input = RadianceMap;
if(input == null || input.Dimension != TextureDimension.TextureCube)
throw new NotSupportedException("Only cubemaps are currently supported as input");
var roughness = 0f;
var faceCount = output.ArraySize;
var levelSize = new Int2(output.Width, output.Height);
var mipCount = MipmapGenerationCount == 0 ? output.MipLevels : MipmapGenerationCount;
for (int l = 0; l < mipCount; l++)
{
if (l == 0 && DoNotFilterHighestLevel && input.Width >= output.Width)
{
var inputLevel = MathUtil.Log2(input.Width / output.Width);
for (int f = 0; f < 6; f++)
{
var inputSubresource = inputLevel + f * input.MipLevels;
var outputSubresource = 0 + f * output.MipLevels;
GraphicsDevice.CopyRegion(input, inputSubresource, null, output, outputSubresource);
}
}
else
{
var outputView = output.ToTextureView(ViewType.MipBand, 0, l);
computeShader.ThreadGroupCounts = new Int3(levelSize.X, levelSize.Y, faceCount);
computeShader.ThreadNumbers = new Int3(SamplingsCount, 1, 1);
computeShader.Parameters.Set(RadiancePrefilteringGGXShaderKeys.Roughness, roughness);
computeShader.Parameters.Set(RadiancePrefilteringGGXShaderKeys.MipmapCount, input.MipLevels - 1);
computeShader.Parameters.Set(RadiancePrefilteringGGXShaderKeys.RadianceMap, input);
computeShader.Parameters.Set(RadiancePrefilteringGGXShaderKeys.RadianceMapSize, input.Width);
computeShader.Parameters.Set(RadiancePrefilteringGGXShaderKeys.FilteredRadiance, outputView);
computeShader.Parameters.Set(RadiancePrefilteringGGXParams.NbOfSamplings, SamplingsCount);
computeShader.Draw(context);
outputView.Dispose();
}
if (mipCount > 1)
{
roughness += 1f / (mipCount - 1);
levelSize /= 2;
}
}
}
开发者ID:Powerino73,项目名称:paradox,代码行数:51,代码来源:RadiancePrefilteringGGX.cs
示例7: BackgroundSection
public BackgroundSection(Sprite backgroundSprite, Vector3 screenVirtualResolution, float scrollSpeed, float depth, Vector2 startPos = default(Vector2))
{
screenResolution = new Int2((int)screenVirtualResolution.X, (int)screenVirtualResolution.Y);
screenCenter = new Vector2(screenVirtualResolution.X / 2, screenVirtualResolution.Y /2);
this.depth = depth;
firstQuadPos = startPos;
secondQuadPos = startPos;
ScrollSpeed = scrollSpeed;
ScrollPos = 0;
CreateBackground(backgroundSprite.Texture, backgroundSprite.Region);
}
开发者ID:Kryptos-FR,项目名称:xenko-reloaded,代码行数:14,代码来源:BackgroundSection.cs
示例8: DrawTo
/// <summary>
/// Draws to the specified cube at the specified position.
/// </summary>
/// <param name='position'>
/// Position (from bottom left).
/// </param>
/// <param name='cube'>
/// Cube.
/// </param>
public override void DrawTo(Int2 position, Cube cube)
{
base.DrawTo(position, cube);
switch (id)
{
case 0:
cube.FillRect(new Color(128,128,255), Cube.SCREEN_WIDTH/2, Cube.SCREEN_HEIGHT/2-10, 1, 20);
break;
case 1:
cube.FillRect(new Color(128,128,255), Cube.SCREEN_WIDTH/2-4, Cube.SCREEN_HEIGHT/2-10, 1, 20);
cube.FillRect(new Color(128,128,255), Cube.SCREEN_WIDTH/2+4, Cube.SCREEN_HEIGHT/2-10, 1, 20);
break;
}
}
开发者ID:dennispr,项目名称:Reunion,代码行数:23,代码来源:Player.cs
示例9: BeadSelectorDlg
public BeadSelectorDlg(FloatImg image, int ROI, Int2[] positions)
{
InitializeComponent();
if (!DesignMode)
{
dispImage = image.ToImage();
this.image = image;
pictureBox.Image = dispImage;
roiPositions = positions.ToList();
}
DialogResult = System.Windows.Forms.DialogResult.Cancel;
textBoxROI.Text = ROI.ToString();
}
开发者ID:,项目名称:,代码行数:14,代码来源:
示例10: FixedUpdate
void FixedUpdate() {
mousePos = Input.mousePosition;
foreach (var town in Towns)
{
Int2 mousePosInt = new Int2();
Tile.ScreenToMapPosition(mousePos, out mousePosInt);
if (Vector2.Distance(town.location.ToVector2(), mousePosInt.ToVector2()) < .32f)
{
selectedTownPos = Tile.MapToWorldPosition(town.location);
selectedTownName = town.name;
print(town.name);
}
}
}
开发者ID:lauhau,项目名称:projectRL,代码行数:15,代码来源:Map.cs
示例11: Update
// Update is called once per frame
void Update () {
// Calculate the tile the target is standing on
Int2 p = new Int2 ( Mathf.RoundToInt ((target.position.x - tileSize*0.5f) / tileSize), Mathf.RoundToInt ((target.position.z - tileSize*0.5f) / tileSize) );
// Clamp range
range = range < 1 ? 1 : range;
// Remove tiles which are out of range
bool changed = true;
while ( changed ) {
changed = false;
foreach (KeyValuePair<Int2,ProceduralTile> pair in tiles ) {
if ( Mathf.Abs (pair.Key.x-p.x) > range || Mathf.Abs (pair.Key.y-p.y) > range ) {
pair.Value.Destroy ();
tiles.Remove ( pair.Key );
changed = true;
break;
}
}
}
// Add tiles which have come in range
// and start calculating them
for ( int x = p.x-range; x <= p.x+range; x++ ) {
for ( int z = p.y-range; z <= p.y+range; z++ ) {
if ( !tiles.ContainsKey ( new Int2(x,z) ) ) {
ProceduralTile tile = new ProceduralTile ( this, x, z );
var generator = tile.Generate ();
// Tick it one step forward
generator.MoveNext ();
// Calculate the rest later
tileGenerationQueue.Enqueue (generator);
tiles.Add ( new Int2(x,z), tile );
}
}
}
// The ones directly adjacent to the current one
// should always be completely calculated
// make sure they are
for ( int x = p.x-1; x <= p.x+1; x++ ) {
for ( int z = p.y-1; z <= p.y+1; z++ ) {
tiles[new Int2(x,z)].ForceFinish();
}
}
}
开发者ID:dwinings,项目名称:ggj16_team_winings,代码行数:49,代码来源:ProceduralWorld.cs
示例12: SetUp
public void SetUp()
{
var x = 50;
var y = 75;
var width = 100;
var height = 125;
_aabb = new AABB(x, y, width, height);
_top = y;
_left = x;
_right = x + width;
_bottom = y + height;
_topLeft = new Int2(_left, _top);
_topRight = new Int2(_right, _top);
_bottomLeft = new Int2(_left, _bottom);
_bottomRight = new Int2(_right, _bottom);
}
开发者ID:veatchje,项目名称:Siftables-477,代码行数:16,代码来源:AABBTests.cs
示例13: Combine
public static PlatformGroup Combine(PlatformGroup lhs, PlatformGroup rhs, Int2 playerIdx)
{
GameObject output = new GameObject("PlatformGroup");
PlatformGroup outputGroup = output.AddComponent<PlatformGroup>();
outputGroup.container = new HashSet<Platform>();
//outputGroup.OnGroupMoved += robot.replanPath;
//transfer ownership
outputGroup.container.UnionWith(lhs.container);
outputGroup.container.UnionWith(rhs.container);
//transfer childObjs
List<Transform> children = new List<Transform>();
for (int i = 0; i < lhs.gameObject.transform.childCount; i++)
children.Add(lhs.gameObject.transform.GetChild(i));
foreach (Transform child in children)
child.transform.parent = output.transform;
children.Clear();
for (int i = 0; i < rhs.gameObject.transform.childCount; i++)
children.Add(rhs.gameObject.transform.GetChild(i));
foreach (Transform child in children)
child.transform.parent = output.transform;
//Vector2 robotPos2d = new Vector2(robot.transform.position.x, robot.transform.position.z);
if (ReferenceEquals(lhs, gridSystem.ComputeGroup(playerIdx)) ||
ReferenceEquals(rhs, gridSystem.ComputeGroup(playerIdx)) ||
ReferenceEquals(lhs, gridSystem.ComputeGroup(gridSystem.goal)) ||
ReferenceEquals(rhs, gridSystem.ComputeGroup(gridSystem.goal)))
{
foreach (Transform child in output.transform)
child.gameObject.layer = Utility.ToLayerNumber(gridSystem.lockedPfLayer);//?
}
foreach (Platform pf in outputGroup.container)
pf.group = outputGroup;
lhs.container.Clear();
rhs.container.Clear();
Destroy(lhs.gameObject);
Destroy(rhs.gameObject);
return outputGroup;
}
开发者ID:MangoSister,项目名称:Space-Escape,代码行数:45,代码来源:PlatformGroup.cs
示例14: CharacterBitmap
/// <summary>
/// Initializes a new instance of the <see cref="CharacterBitmap"/> class from a data array.
/// </summary>
/// <param name="pixelMode">The data format of the bitmap data</param>
/// <param name="data">The bitmap data</param>
/// <param name="borderSize">The size of the border around the image</param>
/// <param name="width">The width of the bitmap </param>
/// <param name="rows">The height of the bitmap</param>
/// <param name="pitch">The pitch of the bitmap</param>
/// <param name="grayLevels">The number of gray levels of the bitmap</param>
public CharacterBitmap(IntPtr data, ref Int2 borderSize, int width, int rows, int pitch, int grayLevels, PixelMode pixelMode)
{
// add one empty border to each side of the bitmap
width += 2 * borderSize.X;
rows += 2 * borderSize.Y;
buffer = Utilities.AllocateMemory(width * rows, 1);
if (pixelMode == PixelMode.Mono)
CopyAndAddBordersFromMono(data, buffer, ref borderSize, width, rows, pitch);
else
CopyAndAddBordersFromGrays(data, buffer, ref borderSize, width, rows);
this.width = width;
this.rows = rows;
this.pitch = width;
this.grayLevels = grayLevels;
this.pixelMode = pixelMode;
}
开发者ID:Powerino73,项目名称:paradox,代码行数:29,代码来源:CharacterBitmap.cs
示例15: ExecuteAlgorithm
public int[,] ExecuteAlgorithm(int numTiles, out List<Vector2> openPositions, out Vector3 playerSpawn)
{
openPositions = new List<Vector2>();
int[,] level = new int[numTiles * 2, numTiles * 2];
set2DArrayDefaults(level, 2);
int startingX = numTiles, startingY = numTiles;
Int2 current = new Int2(startingX, startingY);
Int2 directionLastMoved = new Int2(0, 0);
int numTilesPlaced = 0;
// For resizing the level
int leftX = current.x;
int rightX = current.x;
int topY = current.y;
int bottomY = current.y;
while (numTilesPlaced < numTiles)
{
leftX = current.x < leftX ? current.x : leftX;
rightX = current.x > rightX ? current.x : rightX;
topY = current.y > topY ? current.y : topY;
bottomY = current.y < bottomY ? current.y : bottomY;
if (level[current.x, current.y] == 2)
{
level[current.x, current.y] = 1;
numTilesPlaced++;
}
current += getRandomDirection(new int[] { 25, 25, 25, 25 });
}
playerSpawn = new Vector3((startingY - bottomY + 1) * LoadLevel.TileSize, (startingX - leftX + 1) * LoadLevel.TileSize, 0);
return cropLevel(level, leftX, rightX, topY, bottomY, openPositions);
}
开发者ID:drzaal,项目名称:space-soldier,代码行数:40,代码来源:BasicLevelAlgorithm.cs
示例16: FieldPlane
public FieldPlane(Plane plane, Texture2D field, Int2 texSize, float timeSlice = 0, float invalidValue = float.MaxValue, RenderEffect effect = RenderEffect.DEFAULT, Colormap map = Colormap.Parula)
{
this._effect = _planeEffect;
this._vertexSizeBytes = 32;
this._numVertices = 6;
this.UsedMap = map;
this._width = texSize.X;
this._height = texSize.Y;
this._invalid = invalidValue;
// Setting up the vertex buffer.
GenerateGeometry(plane, texSize, timeSlice);
// Generating Textures from the fields.
_fieldTextures = new ShaderResourceView[1];
_fieldTextures[0] = new ShaderResourceView(_device, field);
this.SetRenderEffect(effect);
this._vertexLayout = new InputLayout(_device, _technique.GetPassByIndex(0).Description.Signature, new[] {
new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0),
new InputElement("TEXTURE", 0, Format.R32G32B32A32_Float, 16, 0)
});
}
开发者ID:AnkeAnke,项目名称:FlowSharp,代码行数:23,代码来源:Plane.cs
示例17: CopyAndAddBordersFromGrays
private static unsafe void CopyAndAddBordersFromGrays(IntPtr data, IntPtr dataBytes, ref Int2 borderSize, int width, int rows)
{
var widthLessBorders = width - (borderSize.X << 1);
var rowsLessBorders = rows - (borderSize.Y << 1);
var resetBorderLineSize = width * borderSize.Y;
Utilities.ClearMemory(dataBytes, 0, resetBorderLineSize);
Utilities.ClearMemory(dataBytes + width * rows - resetBorderLineSize, 0, resetBorderLineSize); // set last border lines to null
var src = (byte*)data;
var dst = (byte*)dataBytes + resetBorderLineSize;
// set the middle of the image
for (int row = 0; row < rowsLessBorders; row++)
{
for (int c = 0; c < borderSize.X; c++)
{
*dst = 0;
++dst;
}
for (int c = 0; c < widthLessBorders; c++)
{
*dst = *src;
++dst;
++src;
}
for (int c = 0; c < borderSize.X; c++)
{
*dst = 0;
++dst;
}
}
}
开发者ID:Powerino73,项目名称:paradox,代码行数:36,代码来源:CharacterBitmap.cs
示例18: setTiles
void setTiles(int[,] generatedLevel, Vector3 playerSpawn, GameObject player)
{
Int2 mapDimensions = new Int2(generatedLevel.GetLength(1), generatedLevel.GetLength(0));
// create level
Tile.NewLevel(mapDimensions, 0, TILE_SIZE, 0, LayerLock.None);
Tile.AddLayer(mapDimensions, 0, TILE_SIZE, 0, LayerLock.None);
// set sorting layers
Tile.SetLayerSorting(0, 0);
Tile.SetLayerSorting(1, 1);
// set collider layer so that walls can be detected by raycasting
Tile.SetColliderLayer(WALL_LAYER);
for (int row = 0; row < generatedLevel.GetLength(0); row++)
{
for (int col = 0; col < generatedLevel.GetLength(1); col++)
{
Int2 tileLocation = new Int2(col, row);
bool isWall = WALL_INDICES.Contains(generatedLevel[row, col]);
int tileIndex = generatedLevel[row, col];
int spriteTileLayerIndex = isWall ? 1 : 0;
Tile.SetTile(tileLocation, spriteTileLayerIndex, 0, tileIndex, false);
if (isWall && hasAdjacentFloor(generatedLevel, row, col))
{
Tile.SetCollider(tileLocation, 1, true);
}
}
}
StartCoroutine("ConfigureColliders");
player.GetComponent<Rigidbody2D>().position = playerSpawn;
}
开发者ID:charleslee98006,项目名称:space-soldier,代码行数:36,代码来源:LoadLevel.cs
示例19: FindSpriteRegion
/// <summary>
/// Find the region of the texture containing the sprite under the specified pixel.
/// </summary>
/// <param name="texture">The texture containing the sprite</param>
/// <param name="pixel">The coordinate of the pixel specifying the sprite</param>
/// <param name="separatorColor">The separator color that delimit the sprites. If null the <see cref="Color.Transparent"/> color is used</param>
/// <param name="separatorMask">The mask specifying which bits of the color should be checked. The bits are ordered as AABBGGRR.</param>
/// <returns></returns>
public unsafe Rectangle FindSpriteRegion(TexImage texture, Int2 pixel, Color? separatorColor = null, uint separatorMask = 0xff000000)
{
if (texture == null) throw new ArgumentNullException(nameof(texture));
var format = texture.Format;
if (texture.Dimension != TexImage.TextureDimension.Texture2D || !(format.IsRGBAOrder() || format.IsBGRAOrder() || format.SizeInBytes() != 4))
throw new NotImplementedException();
// adjust the separator color the mask depending on the color format.
var separator = (uint)(separatorColor ?? Color.Transparent).ToRgba();
if(texture.Format.IsBGRAOrder())
{
separator = RgbaToBgra(separator);
separatorMask = RgbaToBgra(separatorMask);
}
var maskedSeparator = separator & separatorMask;
var ptr = (uint*)texture.Data;
var stride = texture.RowPitch / 4;
// check for empty region (provided pixel is not valid)
var textureRegion = new Rectangle(0, 0, texture.Width, texture.Height);
if (!textureRegion.Contains(pixel) || (ptr[pixel.Y * stride + pixel.X] & separatorMask) == maskedSeparator)
return new Rectangle(pixel.X, pixel.Y, 0, 0);
// initialize the region with the provided pixel
var region = new Rectangle(pixel.X, pixel.Y, 1, 1);
var nextSearchOffsets = new[,]
{
{ new Int2(-1, -1), new Int2( 0, -1) },
{ new Int2( 1, -1), new Int2( 1, 0) },
{ new Int2( 1, 1), new Int2( 0, 1) },
{ new Int2(-1, 1), new Int2(-1, 0) }
};
var contourLeftEgde = pixel;
var rotationDirection = 0;
do
{
// Stage 1: Find an edge of the shape (look to the left of the provided pixel as long as possible)
var startEdge = contourLeftEgde;
var startEdgeDirection = EdgeDirection.Left;
for (int x = startEdge.X; x >= 0; --x)
{
if ((ptr[startEdge.Y * stride + x] & separatorMask) == maskedSeparator)
break;
startEdge.X = x;
}
// Stage 2: Determine the whole contour of the shape and update the region.
// Note: the found contour can correspond to an internal hole contour or the external shape contour.
var currentEdge = startEdge;
var currentEdgeDirection = startEdgeDirection;
do
{
var previousEdgeDirection = currentEdgeDirection;
var diagonalPixel = currentEdge + nextSearchOffsets[(int)currentEdgeDirection, 0];
var diagonalIsSeparator = !textureRegion.Contains(diagonalPixel) || (ptr[diagonalPixel.Y * stride + diagonalPixel.X] & separatorMask) == maskedSeparator;
var neighbourPixel = currentEdge + nextSearchOffsets[(int)currentEdgeDirection, 1];
var neighbourIsSeparator = !textureRegion.Contains(neighbourPixel) || (ptr[neighbourPixel.Y * stride + neighbourPixel.X] & separatorMask) == maskedSeparator;
// determine the next edge position
if (!diagonalIsSeparator)
{
currentEdge = diagonalPixel;
currentEdgeDirection = (EdgeDirection)(((int)currentEdgeDirection + 3) % 4);
}
else if (!neighbourIsSeparator)
{
currentEdge = neighbourPixel;
}
else
{
currentEdgeDirection = (EdgeDirection)(((int)currentEdgeDirection + 1) % 4);
}
// keep record of the point of the edge which is
if (currentEdge.X < contourLeftEgde.X)
contourLeftEgde = currentEdge;
// increase or decrease the rotation counter based on the sequence of edge direction
rotationDirection += RotationDirection(previousEdgeDirection, currentEdgeDirection);
// update the rectangle
region = Rectangle.Union(region, currentEdge);
}
while (currentEdge != startEdge || currentEdgeDirection != startEdgeDirection); // as long as we do not close the contour continue to explore
} // repeat the process as long as the edge found is not the shape external contour.
//.........这里部分代码省略.........
开发者ID:Kurooka,项目名称:paradox,代码行数:101,代码来源:TextureTool.cs
示例20: PickColor
/// <summary>
/// Pick the color under the specified pixel.
/// </summary>
/// <param name="texture">The texture</param>
/// <param name="pixel">The coordinate of the pixel</param>
public unsafe Color PickColor(TexImage texture, Int2 pixel)
{
if (texture == null) throw new ArgumentNullException(nameof(texture));
var format = texture.Format;
if (texture.Dimension != TexImage.TextureDimension.Texture2D || !(format.IsRGBAOrder() || format.IsBGRAOrder() || format.SizeInBytes() != 4))
throw new NotImplementedException();
// check that the pixel is inside the texture
var textureRegion = new Rectangle(0, 0, texture.Width, texture.Height);
if (!textureRegion.Contains(pixel))
throw new ArgumentException("The provided pixel coordinate is outside of the texture");
var ptr = (uint*)texture.Data;
var stride = texture.RowPitch / 4;
var pixelColorInt = ptr[stride*pixel.Y + pixel.X];
var pixelColor = format.IsRGBAOrder() ? Color.FromRgba(pixelColorInt) : Color.FromBgra(pixelColorInt);
return pixelColor;
}
开发者ID:Kurooka,项目名称:paradox,代码行数:26,代码来源:TextureTool.cs
注:本文中的Int2类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论