本文整理汇总了C#中Engine.Vector类的典型用法代码示例。如果您正苦于以下问题:C# Vector类的具体用法?C# Vector怎么用?C# Vector使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Vector类属于Engine命名空间,在下文中一共展示了Vector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VectorToDirection
// Take a normalized vector and return the direction it's facing.
// There's a quite of lot of operations here I'm sure it could be made more efficent.
private Direction VectorToDirection(Vector direction)
{
Vector up = new Vector(0, 1, 0);
Vector down = new Vector(0, -1, 0);
Vector left = new Vector(-1, 0, 0);
Vector right = new Vector(1, 0, 0);
double upDiff = Math.Acos(direction.DotProduct(up));
double downDiff = Math.Acos(direction.DotProduct(down));
double leftDiff = Math.Acos(direction.DotProduct(left));
double rightDiff = Math.Acos(direction.DotProduct(right));
double smallest = Math.Min(Math.Min(upDiff, downDiff), Math.Min(leftDiff, rightDiff));
// yes there's a precidence if they're the same value, it doesn't matter
if (smallest == upDiff)
{
return Direction.Up;
}
else if (smallest == downDiff)
{
return Direction.Down;
}
else if (smallest == leftDiff)
{
return Direction.Left;
}
else
{
return Direction.Right;
}
}
示例2: Matrix
public Matrix(Vector x, Vector y, Vector z, Vector o)
{
_m11 = x.X; _m12 = x.Y; _m13 = x.Z;
_m21 = y.X; _m22 = y.Y; _m23 = y.Z;
_m31 = z.X; _m32 = z.Y; _m33 = z.Z;
_m41 = o.X; _m42 = o.Y; _m43 = o.Z;
}
示例3: NextMove
public Vector NextMove(Vector currentPosition, double elapsedTime)
{
_elapsedTime += elapsedTime;
var prng = new Random();
double ranTime = (double) prng.Next(5, 25)/10;
if (currentPosition.X > 600) _lastMove = new Vector(-1, 0, 0);
else if (currentPosition.X < -600) _lastMove = new Vector(1, 0, 0);
else if (currentPosition.Y > 370) _lastMove = new Vector(0, -1, 0);
else if (currentPosition.Y < -370) _lastMove = new Vector(0, 1, 0);
else if (_elapsedTime > ranTime)
{
_elapsedTime = 0;
int ranNum = prng.Next(0, 3);
switch (ranNum)
{
case 0:
_lastMove = new Vector(0, 1, 0);
break;
case 1:
_lastMove = new Vector(1, 0, 0);
break;
case 2:
_lastMove = new Vector(0, -1, 0);
break;
case 3:
_lastMove = new Vector(-1, 0, 0);
break;
}
}
return _lastMove;
}
示例4: Tile
public Tile(string tileName, Texture texture, TileCollision tileCollision, Vector position)
{
TileName = tileName;
TileCollision = tileCollision;
Sprite.Texture = texture;
Sprite.SetPosition(position);
}
示例5: Ship
public Ship(Vector pos, Game game, ParticleEngine particleEngine, Arena arena)
{
position = pos;
gameref = game;
particles = particleEngine;
arenaref = arena;
}
示例6: AddExplosion
public void AddExplosion(Vector position)
{
var explosion = new AnimatedSprite {Texture = _textureManager.Get("explosion")};
explosion.SetAnimation(4, 4);
explosion.SetPosition(position);
_effects.Add(explosion);
}
示例7: CreateText
private void CreateText(double x, double y, double maxWidth)
{
_bitmapText.Clear();
double currentX = 0;
double currentY = 0;
string[] words = _text.Split(' ');
foreach (string word in words)
{
Vector nextWordLength = _font.MeasureFont(word);
if (maxWidth != -1 &&
(currentX + nextWordLength.X) > maxWidth)
{
currentX = 0;
currentY += nextWordLength.Y;
}
string wordWithSpace = word + " "; // add the space character that was removed.
foreach (char c in wordWithSpace)
{
CharacterSprite sprite = _font.CreateSprite(c);
float xOffset = ((float)sprite.Data.XOffset) / 2;
float yOffset = (((float)sprite.Data.Height) * 0.5f) + ((float)sprite.Data.YOffset);
sprite.Sprite.SetPosition(x + currentX + xOffset, y - currentY - yOffset);
currentX += sprite.Data.XAdvance;
_bitmapText.Add(sprite);
}
}
_dimensions = _font.MeasureFont(_text, _maxWidth);
_dimensions.Y = currentY;
SetColor(_color);
}
示例8: Move
public void Move(Vector amount)
{
amount *= Speed;
if (Math.Abs(amount.X) > Math.Abs(amount.Y))
{
if (amount.X > 0)
{
MoveRight();
}
else
{
MoveLeft();
}
}
else
{
if (amount.Y > 0)
{
MoveUp();
}
else
{
MoveDown();
}
}
Sprite.SetPosition(Sprite.GetPosition() + amount);
}
示例9: Enemy
/// <summary>
/// Constructs an enemy given the texture and AI (IEnemyBrain)
/// </summary>
/// <param name="texture">The texture for the enemy</param>
/// <param name="enemyBrain">The AI for the enemy</param>
/// <param name="position">The spawn point for this enemy</param>
public Enemy(Texture texture, IEnemyBrain enemyBrain, Vector position)
{
_enemyBrain = enemyBrain;
Sprite.Texture = texture;
Sprite.SetPosition(position);
RestartShootCountDown();
}
示例10: GetIntersectionDepth
/// <summary>
/// Calculates the signed depth of intersection between two rectangles.
/// </summary>
/// <returns>
/// The amount of overlap between two intersecting rectangles. These
/// depth values can be negative depending on which wides the rectangles
/// intersect. This allows callers to determine the correct direction
/// to push objects in order to resolve collisions.
/// If the rectangles are not intersecting, Vector2.Zero is returned.
/// </returns>
public static Vector GetIntersectionDepth(this RectangleF rectA, RectangleF rectB)
{
// Calculate half sizes.
double halfWidthA = rectA.Width/2.0f;
double halfHeightA = rectA.Height/2.0f;
double halfWidthB = rectB.Width/2.0f;
double halfHeightB = rectB.Height/2.0f;
// Calculate centers.
var centerA = new Vector(rectA.Left + halfWidthA, rectA.Top + halfHeightA, 0);
var centerB = new Vector(rectB.Left + halfWidthB, rectB.Top + halfHeightB, 0);
// Calculate current and minimum-non-intersecting distances between centers.
double distanceX = centerA.X - centerB.X;
double distanceY = centerA.Y - centerB.Y;
double minDistanceX = halfWidthA + halfWidthB;
double minDistanceY = halfHeightA + halfHeightB;
// If we are not intersecting at all, return (0, 0).
if (Math.Abs(distanceX) >= minDistanceX || Math.Abs(distanceY) >= minDistanceY)
return Vector.Zero;
// Calculate and return intersection depths.
double depthX = distanceX > 0 ? minDistanceX - distanceX : -minDistanceX - distanceX;
double depthY = distanceY > 0 ? minDistanceY - distanceY : -minDistanceY - distanceY;
return new Vector(depthX, depthY, 0);
}
示例11: SpawnParticle
//Spawn a new particle
public void SpawnParticle(int timeToLive, Vector position, Vector velocity, Vector accelleration, double red, double green, double blue, double alpha, bool gradualFade, int size)
{
if (particles.Count < maxParticles)
{
particles.Add(new Particle(texture, timeToLive, position, velocity, accelleration, red, green, blue, alpha, gradualFade, size));
}
}
示例12: Update
public void Update(double elapsedTime)
{
// Get controls and apply to player character
double _x = _input.Controller.LeftControlStick.X;
double _y = _input.Controller.LeftControlStick.Y * -1;
Vector controlInput = new Vector(_x, _y, 0);
if (Math.Abs(controlInput.Length()) < 0.0001)
{
// If the input is very small, then the player may not be using
// a controller;, they might be using the keyboard.
if (_input.Keyboard.IsKeyHeld(Keys.Left))
{
controlInput.X = -1;
}
if (_input.Keyboard.IsKeyHeld(Keys.Right))
{
controlInput.X = 1;
}
if (_input.Keyboard.IsKeyHeld(Keys.Up))
{
controlInput.Y = 1;
}
if (_input.Keyboard.IsKeyHeld(Keys.Down))
{
controlInput.Y = -1;
}
}
_playerCharacter.Move(controlInput * elapsedTime);
}
示例13: BasicGroundEnemy
//Character attributes
public BasicGroundEnemy(Game game, Vector position, Vector velocity, Dictionary<string, Sprite> sprites, string defaultSprite, IController controller, //GameObject attributes
WorldPhysics worldPhysics, ObjectPhysics objectPhysics, Dictionary<string, BoundingPolygon> boundingPolygons, //PhysicalObject attributes
double runSpeed, double maxSpeed)
: base(game, position, velocity, sprites, defaultSprite, controller, worldPhysics, objectPhysics, boundingPolygons, runSpeed, maxSpeed)
{
Stompable = true;
}
示例14: EditorModel
public EditorModel()
{
Running = true;
MousePosition = new Vector();
Objects = new List<MapObject>();
ExtraProperties = new Dictionary<string, string>();
}
示例15: CollidableObject
public CollidableObject(double x, double y, Vector v)
{
position = new Vector(x, y);
velocity = v;
LastVelocity = new Vector(0,0);
BoundingBox = new BoundingBox(position.X-width/2, position.Y+height/2, position.X+width/2, position.Y-height/2);
}