public static Matrix44D ToMatrix44D(this CardanFrame eulerFrame) { var alphaRotation = Matrix44D.CreateRotation(new Vector3D(1.0, 0.0, 0.0), eulerFrame.AlphaAngleAxisX); var betaRotation = Matrix44D.CreateRotation(new Vector3D(0.0, 1.0, 0.0), eulerFrame.BetaAngleAxisY); var gammaRotation = Matrix44D.CreateRotation(new Vector3D(0.0, 0.0, 1.0), eulerFrame.GammaAngleAxisZ); var translation = Matrix44D.CreateTranslation(eulerFrame.Translation); var matrix = translation * gammaRotation * betaRotation * alphaRotation; return(matrix); }
public Matrix44D CreateFrame() { var rotAlpha = Matrix44D.CreateRotation(new Vector3D(1, 0, 0), CreateAngle()); var rotBeta = Matrix44D.CreateRotation(new Vector3D(0, 1, 0), CreateAngle()); var rotGamma = Matrix44D.CreateRotation(new Vector3D(0, 0, 1), CreateAngle()); var translation = Matrix44D.CreateTranslation(CreateVector()); var randomMatrix = translation * rotAlpha * rotBeta * rotGamma; return(randomMatrix); }
public static Scene CreateAndPopulateScene() { var scene = new Scene(); var cube = Cube.Create(10.0); cube.Frame = Matrix44D.CreateTranslation(new Vector3D(0, 0, 5)); scene.Bodies.Add(cube); var cube2 = Cube.Create(10.0); cube2.Frame = Matrix44D.CreateTranslation(new Vector3D(0, 0, 15)) * Matrix44D.CreateRotation(new Vector3D(0, 0, 1), 45.0.DegToRad());; cube2.Sensor = new CylinderSensor(new Vector3D(0, 0, 1)); scene.Bodies.Add(cube2); var cylinder = Cylinder.Create(16, 4.0, 10.0); cylinder.Frame = Matrix44D.CreateTranslation(new Vector3D(10, 10, 5.1)); cylinder.Sensor = new LinearSensor(new Vector3D(0, 1, 0)); scene.Bodies.Add(cylinder); var floor = Floor.Create(4, 20); scene.Bodies.Add(floor); double[][] segments = new double[][] { new [] { 0.0, 0.0, 5.0, 0.0 }, new [] { 5.0, 0.0, 5.0, 1.0 }, new [] { 5.0, 1.0, 1.0, 5.0 }, new [] { 1.0, 5.0, 1.0, 7.0 }, new [] { 1.0, 7.0, 5.0, 11.0 }, new [] { 5.0, 11.0, 5.0, 12.0 }, new [] { 5.0, 12.0, 0.0, 12.0 }, }; bool[] borderFlags = new bool[] { true, true, true, true, true, true, true }; bool[] facetsFlags = new bool[] { false, false, false, false, false, false, false }; var rotationBody = RotationBody.Create(16, segments, borderFlags, facetsFlags); rotationBody.Sensor = new PlaneSensor(new Vector3D(0, 0, 1)); rotationBody.Frame = Matrix44D.CreateTranslation(new Vector3D(30, -30, 0.1)); scene.Bodies.Add(rotationBody); var sphere = Sphere.Create(16, 8); sphere.Sensor = new SphereSensor(); sphere.Frame = Matrix44D.CreateTranslation(new Vector3D(-30, 30, 10)); scene.Bodies.Add(sphere); return(scene); }
public void OperatorMultiplyTest_WhenTranslationWithRoationAreMultiplidWithPosition_ThenPositionIsTranslatedAndThenRotated() { var first = Matrix44D.CreateRotation(new Position3D(), new Vector3D(0, 0, 1), 90.0.DegToRad()); var second = Matrix44D.CreateTranslation(new Vector3D(100.0, 0.0, 0.0)); var position = new Position3D(1.0, 0.0, 0.0); var newPosition = first * second * position; var expected = new Position3D(0.0, 101.0, 0.0); Assert.Equal(expected, newPosition); }
private static void Process(LinearSensor linearSensor, Body body, Axis3D startMoveRay, Axis3D endMoveRay) { if (startMoveRay.Offset == endMoveRay.Offset) { return; } var moveVector = CalculateMove(body, linearSensor.Axis, startMoveRay, endMoveRay); var moveFrame = Matrix44D.CreateTranslation(moveVector); body.Frame = moveFrame * body.Frame; }
public static void SetCamera(this Camera camera, Position3D target, double alpha, double beta, double distance) { alpha = alpha.DegToRad(); beta = beta.DegToRad(); var rotAlpha = Matrix44D.CreateRotation(new Position3D(), new Vector3D(0, 0, 1), alpha); var rotBeta = Matrix44D.CreateRotation(new Position3D(), new Vector3D(1, 0, 0), -beta); var translation = Matrix44D.CreateTranslation(new Vector3D(0.0, -distance, 0.0)); var targetTranslation = Matrix44D.CreateTranslation(camera.Target.ToVector3D()); var frame = targetTranslation * rotAlpha * rotBeta * translation; camera.Frame = frame; camera.Target = target; }
public void CreateTranslationTest_WhenCreateTranslationIsCalledWithOffset_ThenTranslationIsOffsetAndExEyEzAreCoordinateAxes() { var offset = new Vector3D(2.0, 3.0, 4.0); var mat = Matrix44D.CreateTranslation(offset); }