public override void Update(IEnumerable <Entity> entities) { angle += Time.Delta * Speed; angle = MathExtensions.WrapRotationToMinus180ToPlus180(angle); SunLight.Current.Direction = new Vector3D(MathExtensions.Cos(angle), MathExtensions.Sin(angle), 1.0f); }
public static Quaternion FromAxisAngle(Vector3D axis, float angle) { var vectorPart = MathExtensions.Sin(angle * 0.5f) * axis; return(new Quaternion(vectorPart.X, vectorPart.Y, vectorPart.Z, MathExtensions.Cos(angle * 0.5f))); }
public void Cos() { Assert.AreEqual(1, MathExtensions.Cos(0)); Assert.AreEqual(0, MathExtensions.Cos(90), Precision); Assert.AreEqual(-1, MathExtensions.Cos(180), Precision); Assert.AreEqual(1, MathExtensions.Cos(360), Precision); Assert.AreNotEqual(0, MathExtensions.Cos(32)); }
private static Vector3D CalculateCirclePoint(float radius, float distanceToGround, int pointCount, float theta) { float x = radius * MathExtensions.Cos(pointCount * theta); float y = radius * MathExtensions.Sin(pointCount * theta); return(new Vector3D(x, y, distanceToGround)); }
private void FormRotatedEllipsePoint(int i) { var ellipsePoint = new Vector2D(radiusX * MathExtensions.Sin(i * theta), radiusY * MathExtensions.Cos(i * theta)); ellipsePoints.Add(center + ellipsePoint.RotateAround(Vector2D.Zero, rotationSin, rotationCos)); }
private void ProcessRotation(float rotation) { isRotated = rotation != 0.0f; if (!isRotated) { return; } sin = MathExtensions.Sin(rotation); cos = MathExtensions.Cos(rotation); }
public double GetBrightness(Point lightPoint, double ia, double ka, double il, double kd) { var vector = MathExtensions.Vectorize(lightPoint, CentralPoint); var angleCos = MathExtensions.Cos(Normal, vector); angleCos = angleCos < 0 ? 0 : angleCos; var brightness = ia * ka + il * kd * angleCos; brightness = brightness / 255; return(brightness); }
private void AddVerticesRotated(Sprite sprite, Vector2D rotationCenter) { float sin = MathExtensions.Sin(rotation); float cos = MathExtensions.Cos(rotation); if (!hasUV) { var color = sprite.Color; verticesColor[verticesIndex++] = new VertexPosition2DColor( ScreenSpace.Current.ToPixelSpaceRounded( drawArea.TopLeft.RotateAround(rotationCenter, sin, cos)), color); verticesColor[verticesIndex++] = new VertexPosition2DColor( ScreenSpace.Current.ToPixelSpaceRounded( drawArea.BottomLeft.RotateAround(rotationCenter, sin, cos)), color); verticesColor[verticesIndex++] = new VertexPosition2DColor( ScreenSpace.Current.ToPixelSpaceRounded( drawArea.BottomRight.RotateAround(rotationCenter, sin, cos)), color); verticesColor[verticesIndex++] = new VertexPosition2DColor( ScreenSpace.Current.ToPixelSpaceRounded( drawArea.TopRight.RotateAround(rotationCenter, sin, cos)), color); } else if (hasColor) { var color = sprite.Color; verticesColorUV[verticesIndex++] = new VertexPosition2DColorUV( ScreenSpace.Current.ToPixelSpaceRounded( drawArea.TopLeft.RotateAround(rotationCenter, sin, cos)), color, uv.TopLeft); verticesColorUV[verticesIndex++] = new VertexPosition2DColorUV( ScreenSpace.Current.ToPixelSpaceRounded( drawArea.BottomLeft.RotateAround(rotationCenter, sin, cos)), color, uv.BottomLeft); verticesColorUV[verticesIndex++] = new VertexPosition2DColorUV( ScreenSpace.Current.ToPixelSpaceRounded( drawArea.BottomRight.RotateAround(rotationCenter, sin, cos)), color, uv.BottomRight); verticesColorUV[verticesIndex++] = new VertexPosition2DColorUV( ScreenSpace.Current.ToPixelSpaceRounded( drawArea.TopRight.RotateAround(rotationCenter, sin, cos)), color, uv.TopRight); } else { verticesUV[verticesIndex++] = new VertexPosition2DUV( screen.ToPixelSpaceRounded(drawArea.TopLeft.RotateAround(rotationCenter, sin, cos)), uv.TopLeft); verticesUV[verticesIndex++] = new VertexPosition2DUV( screen.ToPixelSpaceRounded(drawArea.BottomLeft.RotateAround(rotationCenter, sin, cos)), uv.BottomLeft); verticesUV[verticesIndex++] = new VertexPosition2DUV( screen.ToPixelSpaceRounded(drawArea.BottomRight.RotateAround(rotationCenter, sin, cos)), uv.BottomRight); verticesUV[verticesIndex++] = new VertexPosition2DUV( screen.ToPixelSpaceRounded(drawArea.TopRight.RotateAround(rotationCenter, sin, cos)), uv.TopRight); } }
public void CreateQuaternionFromAxisAngle() { var axis = Vector3D.UnitY; const float Angle = 90.0f; var quaternion = Quaternion.FromAxisAngle(axis, Angle); var sinHalfAngle = MathExtensions.Sin(Angle * 0.5f); Assert.AreEqual(quaternion.X, axis.X * sinHalfAngle); Assert.AreEqual(quaternion.Y, axis.Y * sinHalfAngle); Assert.AreEqual(quaternion.Z, axis.Z * sinHalfAngle); Assert.AreEqual(quaternion.W, MathExtensions.Cos(Angle * 0.5f)); }
private static Matrix GetBoneTransform(int frameIndex, int boneIndex) { if (boneIndex != (NumberOfBones - 1)) { return(Matrix.Identity); } float circleStep = ((float)frameIndex / NumberOfAnimationFrames) * 360.0f; const float AnimationMaximumBendAngle = 45.0f; return(Matrix.CreateRotationZYX(MathExtensions.Sin(circleStep) * AnimationMaximumBendAngle, MathExtensions.Sin(circleStep) * AnimationMaximumBendAngle, MathExtensions.Cos(circleStep) * AnimationMaximumBendAngle)); }
private Vector2f GetNewVelocity(Vector2f velocity, Collision collision) { var currentAngle = Math.Atan2(-velocity.Y, -velocity.X); var collisionAngle = Math.Atan2(collision.Normal.Y, collision.Normal.X); var exitAngle = collisionAngle + (collisionAngle - currentAngle); var normalisedVelocity = velocity.Normalize(); var currentSpeed = velocity.Magnitude() * 0.45f; var exitVector = new Vector2f(MathExtensions.Cos(exitAngle), MathExtensions.Sin(exitAngle)); exitVector *= currentSpeed; return(exitVector); }
private static void CreatePolygon(Vector2D position, float radius, Color color) { var polygon = new Polygon2D(Rectangle.FromCenter(position, new Size(radius)), color); var points = new List <Vector2D> { polygon.Center }; for (int num = 0; num <= 500; num++) { points.Add(polygon.Center + new Vector2D(radius * MathExtensions.Sin(num * 360.0f / 500.0f), radius * MathExtensions.Cos(num * 360.0f / 500.0f))); } polygon.Points.AddRange(points); }
//ncrunch: no coverage start public Projectile(Vector2D startPosition, float angle) : base(Rectangle.FromCenter(startPosition, new Size(.02f))) { Rotation = angle; RenderLayer = (int)AsteroidsRenderLayer.Rockets; missileAndTrails = new ParticleSystem(ContentLoader.Load <ParticleSystemData>("MissileEffect")); //Replacing usage of the ContentLoader we could do the following to dynamically create data: //missileAndTrails = new ParticleSystem(); //var rocketData = new ParticleEmitterData //{ // ParticleMaterial = ContentLoader.Load<Material>("Missile2D"), // Size = new RangeGraph<Size>(new Size(0.025f, 0.025f), new Size(0.025f, 0.025f)), // LifeTime = 0, // SpawnInterval = 0.001f, // MaximumNumberOfParticles = 1 //}; //var trailData = new ParticleEmitterData //{ // ParticleMaterial = ContentLoader.Load<Material>("Projectile2D"), // Size = new RangeGraph<Size>(new Size(0.02f, 0.03f), new Size(0.02f, 0.04f)), // StartPosition = // new RangeGraph<Vector3D>(new Vector3D(0.0f, 0.02f, 0.0f), new Vector3D(0.0f, 0.02f, 0.0f)), // LifeTime = 2.2f, // SpawnInterval = 0.2f, // MaximumNumberOfParticles = 8 //}; //missileAndTrails.AttachEmitter(new ParticleEmitter(trailData, Vector3D.Zero)); //missileAndTrails.AttachEmitter(new ParticleEmitter(rocketData, Vector3D.Zero)); //missileAndTrails.AttachedEmitters[0].EmitterData.DoParticlesTrackEmitter = true; //missileAndTrails.AttachedEmitters[1].EmitterData.DoParticlesTrackEmitter = true; //foreach (var emitter in missileAndTrails.AttachedEmitters) // emitter.EmitterData.StartRotation = // new RangeGraph<ValueRange>(new ValueRange(Rotation, Rotation), // new ValueRange(Rotation, Rotation)); missileAndTrails.Orientation = Quaternion.FromAxisAngle(Vector3D.UnitZ, Rotation); var data = new SimplePhysics.Data { Gravity = Vector2D.Zero, Velocity = new Vector2D(MathExtensions.Sin(angle) * ProjectileVelocity, -MathExtensions.Cos(angle) * ProjectileVelocity) }; Add(data); Start <MoveAndDisposeOnBorderCollision>(); }
private void InitializeVariables(Ellipse entity) { var rotation = entity.Rotation; rotationSin = MathExtensions.Sin(rotation); rotationCos = MathExtensions.Cos(rotation); rotationCenter = entity.RotationCenter; center = entity.DrawArea.Center; if (center != rotationCenter) { center = center.RotateAround(rotationCenter, rotationSin, rotationCos); } radiusX = entity.RadiusX; radiusY = entity.RadiusY; float maxRadius = MathExtensions.Max(radiusX, radiusY); pointsCount = GetPointsCount(maxRadius); theta = -360.0f / (pointsCount - 1); }
private static void DoSomeMaths() { MathExtensions.Sin(12345); MathExtensions.Cos(54321); }
public Vector2D RotateAround(Vector2D center, float angleInDegrees) { return(RotateAround(center, MathExtensions.Sin(angleInDegrees), MathExtensions.Cos(angleInDegrees))); }
public void Accelerate(float magnitude, float angle) { Velocity = new Vector2D(velocity.X + MathExtensions.Sin(angle) * magnitude, velocity.Y - MathExtensions.Cos(angle) * magnitude); }