private void ComputeDisplayParametersForThumbnail() { if (currentConstellation == "Error") { return; } IPlace target = Constellations.ConstellationCentroids[currentConstellation]; Lineset boundries = Constellations.boundries[currentConstellation]; Vector3[] points = new Vector3[boundries.Points.Count]; Vector3[] pointsOut = new Vector3[boundries.Points.Count]; for (int i = 0; i < points.Length; i++) { points[i] = Coordinates.GeoTo3d(boundries.Points[i].Dec, boundries.Points[i].RA); } Matrix mat = Matrix.RotationY((float)(-(24 - (target.RA + 6)) / 12 * Math.PI)); mat = Matrix.Multiply(mat, Matrix.RotationX((float)(target.Lat / 180f * Math.PI))); mat = Matrix.Multiply(mat, Matrix.Scaling(50, -50, 50)); mat = Matrix.Multiply(mat, Matrix.Translation(48, 22, 0)); // mat.Translate(58, 33,0); Vector3.TransformCoordinate(points, ref mat, pointsOut); lines = new PointF[points.Length + 1]; int index = 0; foreach (Vector3 point in pointsOut) { lines[index++] = new PointF((float)point.X, (float)point.Y); } lines[index] = lines[0]; }
public static Matrix4 FromSharpDXMatrix(SharpDX.Matrix m) { m = SharpDX.Matrix.Transpose(m); Matrix4 result = Matrix4.Identity; result.M11 = m.M11; result.M12 = m.M12; result.M13 = m.M13; result.M14 = m.M14; result.M21 = m.M21; result.M22 = m.M22; result.M23 = m.M23; result.M24 = m.M24; result.M31 = m.M31; result.M32 = m.M32; result.M33 = m.M33; result.M34 = m.M34; result.M41 = m.M41; result.M42 = m.M42; result.M43 = m.M43; result.M44 = m.M44; return(result); }
public static VRageMath.Matrix ToXNA(SharpDX.Matrix matrix) { return(new VRageMath.Matrix(matrix.M11, matrix.M12, matrix.M13, matrix.M14, matrix.M21, matrix.M22, matrix.M23, matrix.M24, matrix.M31, matrix.M32, matrix.M33, matrix.M34, matrix.M41, matrix.M42, matrix.M43, matrix.M44)); }
public void Draw(EngineTime time, ref SharpDX.Matrix world, ref SharpDX.Matrix view, ref SharpDX.Matrix projection) { foreach (var component in this.OfType <IDrawable3DComponent>().Where(c => c.IsVisible).ToArray()) { component.Draw(time, ref world, ref view, ref projection); } }
public SharpDX.Matrix ToMatrix(Vector3 origin = default(Vector3)) { float radPitch = (float)(this.Pitch * Math.PI / 180f); float radYaw = (float)(this.Yaw * Math.PI / 180f); float radRoll = (float)(this.Roll * Math.PI / 180f); float SP = (float)Math.Sin(radPitch); float CP = (float)Math.Cos(radPitch); float SY = (float)Math.Sin(radYaw); float CY = (float)Math.Cos(radYaw); float SR = (float)Math.Sin(radRoll); float CR = (float)Math.Cos(radRoll); SharpDX.Matrix m = new SharpDX.Matrix(); m[0, 0] = CP * CY; m[0, 1] = CP * SY; m[0, 2] = SP; m[0, 3] = 0f; m[1, 0] = SR * SP * CY - CR * SY; m[1, 1] = SR * SP * SY + CR * CY; m[1, 2] = -SR * CP; m[1, 3] = 0f; m[2, 0] = -(CR * SP * CY + SR * SY); m[2, 1] = CY * SR - CR * SP * SY; m[2, 2] = CR * CP; m[2, 3] = 0f; m[3, 0] = origin.X; m[3, 1] = origin.Y; m[3, 2] = origin.Z; m[3, 3] = 1f; return(m); }
/// <summary> /// Initializes a new instance of the <see cref="MeshCache"/> class. /// </summary> /// <param name="vertexBuffer">The vertex buffer.</param> /// <param name="tagGroups">The tag groups.</param> /// <param name="localMatrix">The local matrix.</param> public MeshCache(DXBuffer vertexBuffer, IEnumerable<TagGroup> tagGroups, DXMatrix localMatrix) { _vertexBuffer = vertexBuffer; _tagGroups = tagGroups; IsPrelit = false; _localMatrix = localMatrix; }
/// <summary> /// Initializes a new instance of the <see cref="MeshCache"/> class. /// </summary> /// <param name="vertexBuffer">The vertex buffer.</param> /// <param name="tagGroups">The tag groups.</param> public MeshCache(DXBuffer vertexBuffer, IEnumerable<TagGroup> tagGroups) { _vertexBuffer = vertexBuffer; _tagGroups = tagGroups; IsPrelit = false; _localMatrix = DXMatrix.Identity; }
public void SetParameterValue(string p, SharpDX.Matrix value) { if (HasParameter(p)) { effect.Parameters[p].SetValue(value); } }
public void DrawLabels(RenderContext11 renderContext) { if (positions.Count < 1) { return; } InitLabelBuffer(); renderContext.SetVertexBuffer(labelBuffer); renderContext.BlendMode = BlendMode.Alpha; renderContext.DepthStencilMode = DepthStencilMode.Off; renderContext.setRasterizerState(TriangleCullMode.Off); SharpDX.Matrix mvp = (renderContext.World * renderContext.View * renderContext.Projection).Matrix11; mvp.Transpose(); PointSpriteShader11.WVPMatrix = mvp; PointSpriteShader11.Color = SharpDX.Color.White; float adjustedScale = .01f; // (float)(1 / (Earth3d.MainWindow.ZoomFactor / 360)); PointSpriteShader11.ViewportScale = new SharpDX.Vector2((2.0f / renderContext.ViewPort.Width) * adjustedScale, (2.0f / renderContext.ViewPort.Height) * adjustedScale); PointSpriteShader11.PointScaleFactors = new SharpDX.Vector3(0.0f, 0.0f, 10000.0f); PointSpriteShader11.Use(renderContext.Device.ImmediateContext); renderContext.Device.ImmediateContext.PixelShader.SetShaderResource(0, texture.ResourceView); renderContext.devContext.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.PointList; renderContext.devContext.Draw(labelBuffer.Count, 0); renderContext.Device.ImmediateContext.GeometryShader.Set(null); }
public override void Render(DirectXCanvas canvas, ThreadScroll scroll, DirectXCanvas.Layer layer) { if (layer == DirectXCanvas.Layer.Background) { SharpDX.Matrix world = SharpDX.Matrix.Scaling((float)scroll.Zoom, 1.0f, 1.0f); world.TranslationVector = new SharpDX.Vector3(-(float)(scroll.ViewUnit.Left * scroll.Zoom), 0.0f, 0.0f); BackgroundMeshLines.World = world; BackgroundMeshTris.World = world; canvas.Draw(BackgroundMeshTris); canvas.Draw(BackgroundMeshLines); Data.Utils.ForEachInsideInterval(Group.MainThread.Events, scroll.ViewTime, frame => { Interval interval = scroll.TimeToPixel(frame.Header); String text = String.Format(System.Globalization.CultureInfo.InvariantCulture, "{0:0.0} ms", frame.Header.Duration); // 2 times to emulate "bold" for (int i = 0; i < 2; ++i) { canvas.Text.Draw(new Point(interval.Left, Offset), text, TextColor, TextAlignment.Center, interval.Width); } }); } }
/// <summary> /// Draws a line strip in screen space with a specified input transformation matrix. /// </summary> /// <param name="vertices"><para>Array of vertices that make up the line. See <see cref="SharpDX.Vector3"/>.</para></param> /// <param name="transform"><para>A scale, rotate, and translate (SRT) matrix for transforming the points. See <see cref="SharpDX.Matrix"/>. If this matrix is a projection matrix, any stippled lines will be drawn with a perspective-correct stippling pattern. Or, you can transform the vertices and use <see cref="SharpDX.Direct3D9.Line.Draw"/> to draw the line with a nonperspective-correct stipple pattern.</para></param> /// <param name="color"><para>Color of the line. See <see cref="SharpDX.Color4"/>.</para></param> /// <returns>If the method succeeds, the return value is <see cref="SharpDX.Direct3D9.ResultCode.Success"/>. If the method fails, the return value can be one of the following: <see cref="SharpDX.Direct3D9.ResultCode.InvalidCall"/>, D3DXERR_INVALIDDATA.</returns> /// <unmanaged>HRESULT ID3DXLine::DrawTransform([In] const void* pVertexList,[In] unsigned int dwVertexListCount,[In] const D3DXMATRIX* pTransform,[In] D3DCOLOR Color)</unmanaged> public void DrawTransform(Vector3[] vertices, SharpDX.Matrix transform, SharpDX.ColorBGRA color) { unsafe { fixed(void *pVertexListRef = vertices) DrawTransform((IntPtr)pVertexListRef, vertices.Length, ref transform, color); } }
/// <summary> /// Initializes a new instance of the <see cref="MeshCache"/> class. /// </summary> /// <param name="vertexBuffer">The vertex buffer.</param> /// <param name="tagGroups">The tag groups.</param> /// <param name="localMatrix">The local matrix.</param> /// <param name="isPrelit">if set to <c>true</c> [is prelit].</param> /// <param name="tag">The tag.</param> public MeshCache(DXBuffer vertexBuffer, IEnumerable<TagGroup> tagGroups, DXMatrix localMatrix, bool isPrelit, int? tag) { _vertexBuffer = vertexBuffer; _tagGroups = tagGroups; _localMatrix = localMatrix; IsPrelit = isPrelit; Tag = tag; }
public static BulletSharp.Math.Matrix ToBulletSharp(this SharpDX.Matrix value) { return(new BulletSharp.Math.Matrix( value.M11, value.M12, value.M13, value.M14, value.M21, value.M22, value.M23, value.M24, value.M31, value.M32, value.M33, value.M34, value.M41, value.M42, value.M43, value.M44)); }
public static Matrix4x4 ToOwnMatrix(this SharpDX.Matrix m) { return(new Matrix4x4( new float[4, 4] { { m.M11, m.M12, m.M13, m.M14 }, { m.M21, m.M22, m.M23, m.M24 }, { m.M31, m.M32, m.M33, m.M34 }, { m.M41, m.M42, m.M43, m.M44 }, })); }
public static void GetMatrixFromDirection(SharpDX.Vector3 normalizedDirectionVector, SharpDX.Vector3 position, SharpDX.Vector3 scale, out SharpDX.Matrix orientationMatrix) { //var xAxis = normalizedDirectionVector; var yAxis = CalculateUpDirection(normalizedDirectionVector); var zAxis = SharpDX.Vector3.Cross(normalizedDirectionVector, yAxis); // For more info see comments in GetRotationMatrixFromDirection orientationMatrix = new SharpDX.Matrix(normalizedDirectionVector.X * scale.X, normalizedDirectionVector.Y * scale.Y, normalizedDirectionVector.Z * scale.Z, 0, yAxis.X * scale.X, yAxis.Y * scale.Y, yAxis.Z * scale.Z, 0, zAxis.X * scale.X, zAxis.Y * scale.Y, zAxis.Z * scale.Z, 0, position.X, position.Y, position.Z, 1); }
/// <summary> /// Draws a line strip in screen space with a specified input transformation matrix. /// </summary> /// <param name="vertices"><para>Array of vertices that make up the line. See <see cref="SharpDX.Vector3"/>.</para></param> /// <param name="transform"><para>A scale, rotate, and translate (SRT) matrix for transforming the points. See <see cref="SharpDX.Matrix"/>. If this matrix is a projection matrix, any stippled lines will be drawn with a perspective-correct stippling pattern. Or, you can transform the vertices and use <see cref="SharpDX.Direct3D9.Line.Draw"/> to draw the line with a nonperspective-correct stipple pattern.</para></param> /// <param name="color"><para>Color of the line. See <see cref="SharpDX.Color4"/>.</para></param> /// <returns>If the method succeeds, the return value is <see cref="SharpDX.Direct3D9.ResultCode.Success"/>. If the method fails, the return value can be one of the following: <see cref="SharpDX.Direct3D9.ResultCode.InvalidCall"/>, D3DXERR_INVALIDDATA.</returns> /// <unmanaged>HRESULT ID3DXLine::DrawTransform([In] const void* pVertexList,[In] unsigned int dwVertexListCount,[In] const D3DXMATRIX* pTransform,[In] D3DCOLOR Color)</unmanaged> public void DrawTransform <T>(T[] vertices, SharpDX.Matrix transform, SharpDX.ColorBGRA color) where T : struct { unsafe { if (Utilities.SizeOf <T>() != sizeof(Vector3)) { throw new ArgumentException("Invalid size for T. Must be 3 floats (12 bytes)"); } DrawTransform((IntPtr)Interop.Fixed(vertices), vertices.Length, ref transform, color); } }
protected override CameraCore CreatePortableCameraCore() { return(new MatrixCameraCore() { #if NETFX_CORE ProjectionMatrix = this.ProjectionMatrix, ViewMatrix = this.ViewMatrix #else ProjectionMatrix = this.ProjectionMatrix.ToMatrix(), ViewMatrix = this.ViewMatrix.ToMatrix() #endif });
public static CVector ChangeLoadedCurrentAnlorithm(CVector v, DVector n, double angle) { float rangle = (float)(angle / 180 * CV.pi); SharpDX.Matrix m = SharpDX.Matrix.RotationAxis(new SharpDX.Vector3((float)n.X, (float)n.Y, (float)n.Z), rangle); SharpDX.Vector3 reV = new SharpDX.Vector3((float)v.X.Real, (float)v.Y.Real, (float)v.Z.Real); SharpDX.Vector3 imV = new SharpDX.Vector3((float)v.X.Imaginary, (float)v.Y.Imaginary, (float)v.Z.Imaginary); SharpDX.Vector3 reVrot = SharpDX.Vector3.TransformCoordinate(reV, m); SharpDX.Vector3 imVrot = SharpDX.Vector3.TransformCoordinate(imV, m); return(new CVector(new Complex(reVrot.X, imVrot.X), new Complex(reVrot.Y, imVrot.Y), new Complex(reVrot.Z, imVrot.Z))); }
private void Render(DX11RenderContext context, DX11RenderSettings settings) { if (this.spreadMax == 0) { return; } if (this.FInEnabled[0]) { float w = (float)settings.RenderWidth; float h = (float)settings.RenderHeight; SharpDX.Direct3D11.DeviceContext shaprdxContext = new SharpDX.Direct3D11.DeviceContext(context.CurrentDeviceContext.ComPointer); FontWrapper fw = this.FTextRenderer.IsConnected ? this.FTextRenderer[0][context].FontWrapper : FontWrapperFactory.GetWrapper(context, this.dwFactory); var sView = settings.View; var sProj = settings.Projection; SharpDX.Matrix view = *(SharpDX.Matrix *) & sView; SharpDX.Matrix projection = *(SharpDX.Matrix *) & sProj; var objectsettings = this.objectSettings[context]; objectsettings.IterationCount = 1; objectsettings.Geometry = null; for (int i = 0; i < this.textCache.objects.Length; i++) { SharpDX.Matrix mat = SharpDX.Matrix.Scaling(1.0f, -1.0f, 1.0f); mat = SharpDX.Matrix.Multiply(mat, view); mat = SharpDX.Matrix.Multiply(mat, projection); objectsettings.DrawCallIndex = i; objectsettings.WorldTransform = *(SlimDX.Matrix *) & mat; if (settings.ValidateObject(objectsettings)) { SlimDX.Color4 color = this.textCache.objects[i].Color; color.Alpha *= SharpDX.MathUtil.Clamp(settings.LayerOpacity, 0.0f, 1.0f); SharpDX.Color4 sdxColor = *(SharpDX.Color4 *) & color; fw.DrawTextLayout(shaprdxContext, new SharpDX.DirectWrite.TextLayout(this.textCache.objects[i].TextLayout.ComPointer), SharpDX.Vector2.Zero, mat, sdxColor, TextFlags.None); } } //Apply old states back context.RenderStateStack.Apply(); context.CleanShaderStages(); } }
private void DrawFOV(RenderContext11 renderContext, float opacity, double ra, double dec) { Color color = Color.FromArgb((int)(opacity * 255f), Properties.Settings.Default.FovColor); foreach (Imager chip in Camera.Chips) { double halfWidth = (Math.Atan(chip.Width / (2 * Telescope.FocalLength))) / RC; double halfHeight = (Math.Atan(chip.Height / (2 * Telescope.FocalLength))) / RC; double centerOffsetY = 2 * (Math.Atan(chip.CenterY / (2 * Telescope.FocalLength))) / RC; double centerOffsetX = 2 * (Math.Atan(chip.CenterX / (2 * Telescope.FocalLength))) / RC; SharpDX.Matrix mat = SharpDX.Matrix.RotationX((float)(((chip.Rotation + angle)) / 180f * Math.PI)); mat = SharpDX.Matrix.Multiply(mat, SharpDX.Matrix.RotationZ((float)((dec) / 180f * Math.PI))); mat = SharpDX.Matrix.Multiply(mat, SharpDX.Matrix.RotationY((float)(((24 - (ra + 12))) / 12f * Math.PI))); int count = 4; points = new PositionColoredTextured[count + 1]; int index = 0; points[index].Position = RaDecTo3d(-halfWidth + centerOffsetX, -halfHeight + centerOffsetY).Vector4; points[index].Color = color; index++; points[index].Position = RaDecTo3d(halfWidth + centerOffsetX, -halfHeight + centerOffsetY).Vector4; points[index].Color = color; index++; points[index].Position = RaDecTo3d(halfWidth + centerOffsetX, halfHeight + centerOffsetY).Vector4; points[index].Color = color; index++; points[index].Position = RaDecTo3d(-halfWidth + centerOffsetX, halfHeight + centerOffsetY).Vector4; points[index].Color = color; index++; points[index].Position = RaDecTo3d(-halfWidth + centerOffsetX, -halfHeight + centerOffsetY).Vector4; points[index].Color = color; for (int i = 0; i < points.Length; i++) { points[i].Pos3 = SharpDX.Vector3.TransformCoordinate(points[i].Pos3, mat); } SharpDX.Matrix matV = (renderContext.World * renderContext.View * renderContext.Projection).Matrix11; Sprite2d.DrawLines(renderContext, points, 5, matV, true); } }
public override Guid AddInstance(SharpDX.Matrix matrix) { var instance = new InstanceDetails { Id = Guid.NewGuid(), IsVisible = true, Transform = matrix, InstanceParams = defaultInstanceParams }; instances.Add(instance); return(instance.Id); }
public static Matrix GetCameraMatrix() { IntPtr baseAddress = System.Diagnostics.Process.GetCurrentProcess().MainModule.BaseAddress; int length = System.Diagnostics.Process.GetCurrentProcess().MainModule.ModuleMemorySize; Matrix matrix = MemoryAccess.CCamera.GetCurrentCameraMatrix(baseAddress, length); if (matrix != Matrix.Zero) { return(matrix); } else { Log("ERROR: Matrix haven't returned anything!"); return(Matrix.Identity); } }
public SharpDX.Matrix GetViewProjection(System.Drawing.Size size) { SharpDX.Matrix viewMatrix = SharpDX.Matrix.LookAtLH(position, position + SharpDX.Vector3.ForwardLH, SharpDX.Vector3.Up); SharpDX.Matrix projectionMatrix; if (projection.Value == Settings.GraphicsSettings.ProjectionSetting.ORTHOGRAPHIC) { projectionMatrix = SharpDX.Matrix.OrthoOffCenterLH(-1f, 1f, -1f, 1f, 0f, 100f); } else { var fov = (float)System.Math.PI / 3f; var aspect = (float)size.Width / size.Height; projectionMatrix = SharpDX.Matrix.PerspectiveFovLH(fov, aspect, 0f, 100f); } return(viewMatrix * projectionMatrix); }
/// <summary> /// Matrix を、拡大ベクトル・回転行列・平行移動ベクトルに分解する。 /// </summary> /// <remarks> /// 参考: 「その39 知っていると便利?ワールド変換行列から情報を抜き出そう」 /// http://marupeke296.com/DXG_No39_WorldMatrixInformation.html /// </remarks> public static void ToScaleRotationTranslation(this SharpDX.Matrix matrix, out SharpDX.Vector3 scale, out SharpDX.Quaternion rotation, out SharpDX.Vector3 translation) { scale = new SharpDX.Vector3( new SharpDX.Vector3(matrix.M11, matrix.M12, matrix.M13).Length(), new SharpDX.Vector3(matrix.M21, matrix.M22, matrix.M23).Length(), new SharpDX.Vector3(matrix.M31, matrix.M32, matrix.M33).Length()); translation = new SharpDX.Vector3(matrix.M41, matrix.M42, matrix.M43); // matrix を構成する scale と translation が定まれば、rotation も定まる。 // ※参考ページ中段の「WorldMatrix = S・Rx・Ry・Rz・T = ...」の図を参照のこと。 rotation = SharpDX.Quaternion.RotationMatrix( new SharpDX.Matrix { Row1 = (scale.X == 0f) ? SharpDX.Vector4.Zero : new SharpDX.Vector4(matrix.M11 / scale.X, matrix.M12 / scale.X, matrix.M13 / scale.X, 0f), Row2 = (scale.Y == 0f) ? SharpDX.Vector4.Zero : new SharpDX.Vector4(matrix.M21 / scale.Y, matrix.M22 / scale.Y, matrix.M23 / scale.Y, 0f), Row3 = (scale.Z == 0f) ? SharpDX.Vector4.Zero : new SharpDX.Vector4(matrix.M31 / scale.Z, matrix.M32 / scale.Z, matrix.M33 / scale.Z, 0f), Row4 = new SharpDX.Vector4(0f, 0f, 0f, 1f), }); }
public static System.Numerics.Matrix4x4 ToMatrix4x4(this SharpDX.Matrix m) { return(new System.Numerics.Matrix4x4( m.M11, m.M12, m.M13, m.M14, m.M21, m.M22, m.M23, m.M24, m.M31, m.M32, m.M33, m.M34, m.M41, m.M42, m.M43, m.M44)); }
public static void UpdateMatrix() { IntPtr i = Rust.Rust.i; Int64 GameObject = Memory.Memory.Mem.ReadVirtualMemory <Int64>((IntPtr)i + 0x8); UInt64 ObjectClass = Memory.Memory.Mem.ReadVirtualMemory <UInt64>((IntPtr)GameObject + 0x10); UInt64 Entity = Memory.Memory.Mem.ReadVirtualMemory <UInt64>((IntPtr)ObjectClass + 0x30); UInt64 Entity1 = Memory.Memory.Mem.ReadVirtualMemory <UInt64>((IntPtr)Entity + 0x18); SharpDX.Matrix temp_matrix; temp_matrix = Memory.Memory.Mem.ReadVirtualMemory <SharpDX.Matrix>((IntPtr)Entity1 + 0x2e4); temp_matrix.Transpose(); GameMatrix = temp_matrix; return; }
// directionVector must be normalized public static SharpDX.Matrix GetMatrixFromNormalizedDirection(SharpDX.Vector3 normalizedDirectionVector) { // The first three rows in the upper left 3x3 part of the matrix represents the axes of the coordinate system defined by the matrix. // For example in the identity matrix the xAxis is 1,0,0; yAxis is 0,1,0; zAxis is 0,0,1 // With this knowledge we can create a matrix that will orient the transformed positions based on the specified direction vector. // The direction vector represents the xAxis in the new coordinate system. // To get the full matrix, we need to calculate the other two axes. //var xAxis = normalizedDirectionVector; var yAxis = CalculateUpDirectionFromNormalizeDirection(normalizedDirectionVector); // Once we have the direction and up axis, we can get the zAxis with calculating the perpendicular axis to those two var zAxis = SharpDX.Vector3.Cross(normalizedDirectionVector, yAxis); var rotationMatrix = new SharpDX.Matrix(normalizedDirectionVector.X, normalizedDirectionVector.Y, normalizedDirectionVector.Z, 0, yAxis.X, yAxis.Y, yAxis.Z, 0, zAxis.X, zAxis.Y, zAxis.Z, 0, 0, 0, 0, 1); return(rotationMatrix); }
private void Update(EvaluationContext context) { SharpDX.Matrix camToWorld = context.WorldToCamera; camToWorld.Invert(); var pos = SharpDX.Vector4.Transform(new SharpDX.Vector4(0f, 0f, 0f, 1f), camToWorld); Position.Value = new Vector3(pos.X, pos.Y, pos.Z); var dir = SharpDX.Vector4.Transform(new SharpDX.Vector4(0f, 0f, 1f, 1f), camToWorld) - pos; Direction.Value = new Vector3(dir.X, dir.Y, dir.Z); float aspect = context.CameraToClipSpace.M22 / context.CameraToClipSpace.M11; AspectRatio.Value = aspect; Position.DirtyFlag.Clear(); Direction.DirtyFlag.Clear(); AspectRatio.DirtyFlag.Clear(); }
public static Numerics.Matrix4x4 ToNumericsMatrix4x4(this SharpDX.Matrix m) { return(new Numerics.Matrix4x4 { M11 = m.M11, M12 = m.M12, M13 = m.M13, M21 = m.M21, M22 = m.M22, M23 = m.M23, M31 = m.M31, M32 = m.M32, M33 = m.M33, M41 = m.M41, M42 = m.M42, M43 = m.M43 }); }
public bool Frame() { // Check if the user pressed escape and wants to exit the application. if (!Input.Frame() || Input.IsEscapePressed()) { return(false); } // Update the system stats. Timer.Frame2(); if (DPerfLogger.IsTimedTest) { DPerfLogger.Frame(Timer.FrameTime); if (Timer.CumulativeFrameTime >= DPerfLogger.TestTimeInSeconds * 1000) { return(false); } } // The following Rotates the entire scenes around the speakers. // Get current positions of each secondarySound in 3dSpace. SharpDX.Vector3 SoundBufferPosition = Sound._3DSecondarySoundBuffer.Position; // Create a reset Matreix in the o,o,o home position. SharpDX.Matrix rotationMatrix = SharpDX.Matrix.Identity; // Rotate it slightly. rotationMatrix = SharpDX.Matrix.RotationY(0.0002f); // And apply that rotation towards each coordinate for each secondarySoundBuffer being played in 3D space. SharpDX.Vector3 rotatedCoordinates = SharpDX.Vector3.TransformCoordinate(SoundBufferPosition, rotationMatrix); // And assign back the rotated coordinates to each Secondary Soundbuffer that will now been roated. Sound._3DSecondarySoundBuffer.Position = rotatedCoordinates; // Finally render the graphics to the screen. if (!Graphics.Render()) { return(false); } return(true); }
public Rect GetPlacementRect(IntVector3 ml) { // XXX var view = m_game.Surfaces[0].Views[0]; SharpDX.Matrix matrix = view.Camera.View * view.Camera.Projection; var p1 = ml.ToVector3(); var p2 = p1 + new SharpDX.Vector3(1, 1, 0); SharpDX.Vector3 out1, out2; var vp = view.ViewPort; vp.Project(ref p1, ref matrix, out out1); vp.Project(ref p2, ref matrix, out out2); Rect rect = new Rect( DeviceToPoint(new System.Windows.Point(out1.X, out1.Y)), DeviceToPoint(new System.Windows.Point(out2.X, out2.Y))); return(rect); }
public static Matrix RotationVectorFromRotationMatrix(Matrix R) { var sR = new SharpDX.Matrix(); for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) sR[i, j] = (float) R[i, j]; var q = SharpDX.Quaternion.RotationMatrix(sR); var sRotationVector = -q.Angle * q.Axis; var rotationVector = new Matrix(3, 1); for (int i = 0; i < 3; i++) rotationVector[i] = sRotationVector[i]; return rotationVector; }
public static Matrix RotationVectorFromRotationMatrix(Matrix R) { var sR = new SharpDX.Matrix(); for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) sR[i, j] = (float) R[i, j]; var q = SharpDX.Quaternion.RotationMatrix(sR); // Why the negative sign? SharpDX assumes a post-multiply rotation matrix. Instead of transposing the input we invert the output quaternion. var sRotationVector = -q.Angle * q.Axis; var rotationVector = new Matrix(3, 1); for (int i = 0; i < 3; i++) rotationVector[i] = sRotationVector[i]; return rotationVector; }
/// <summary> /// Returns a render view matrix for Direct3D. /// </summary> internal void GetViewMatrix(out DxMatrix4 result) { var m = (DxMatrix4)this; DxMatrix4.Invert(ref m, out result); }
protected void ParseDataObjectAnimationKey(AnimBone animBone) { ReadHeadOfDataObject(); // read key type uint keyType = ReadInt(); // read number of keys uint numKeys = ReadInt(); for (uint a = 0; a < numKeys; a++) { // read time uint time = ReadInt(); // read keys switch (keyType) { case 0: { if (ReadInt() != 4) ThrowException("Invalid number of arguments for quaternion key in animation"); var keyValue = new Quaternion(); keyValue.W = ReadFloat(); keyValue.X = ReadFloat(); keyValue.Y = ReadFloat(); keyValue.Z = ReadFloat(); QuatKey key = new QuatKey((double)time, keyValue); animBone.RotKeys.Add(key); CheckForSemicolon(); break; } case 1: // scale vector case 2: // position vector { // read count if (ReadInt() != 3) { ThrowException("Invalid number of arguments for vector key in animation"); } VectorKey key = new VectorKey((double)time, ReadVector3()); if (keyType == 2) { animBone.PosKeys.Add(key); } else { animBone.ScaleKeys.Add(key); } break; } case 3: case 4: { // read count if (ReadInt() != 16) ThrowException("Invalid number of arguments for matrix key in animation"); // read matrix double key = (double)time; Matrix4x4 value = new Matrix4x4(); value.M11 = ReadFloat(); value.M21 = ReadFloat(); value.M31 = ReadFloat(); value.M41 = ReadFloat(); value.M12 = ReadFloat(); value.M22 = ReadFloat(); value.M32 = ReadFloat(); value.M42 = ReadFloat(); value.M13 = ReadFloat(); value.M23 = ReadFloat(); value.M33 = ReadFloat(); value.M43 = ReadFloat(); value.M14 = ReadFloat(); value.M24 = ReadFloat(); value.M34 = ReadFloat(); value.M44 = ReadFloat(); animBone.TrafoKeys.Add(new MatrixKey(key, value)); CheckForSemicolon(); break; } default: ThrowException(string.Format("Unknown key type {0} in animation.", keyType)); break; } CheckForSeparator(); } CheckForClosingBrace(); }
protected void ParseDataObjectTransformationMatrix(out Matrix4x4 matrix) { // read header, we're not interested if it has a name ReadHeadOfDataObject(); // read its components matrix = new Matrix4x4(); matrix.M11 = ReadFloat(); matrix.M21 = ReadFloat(); matrix.M31 = ReadFloat(); matrix.M41 = ReadFloat(); matrix.M12 = ReadFloat(); matrix.M22 = ReadFloat(); matrix.M32 = ReadFloat(); matrix.M42 = ReadFloat(); matrix.M13 = ReadFloat(); matrix.M23 = ReadFloat(); matrix.M33 = ReadFloat(); matrix.M43 = ReadFloat(); matrix.M14 = ReadFloat(); matrix.M24 = ReadFloat(); matrix.M34 = ReadFloat(); matrix.M44 = ReadFloat(); // trailing symbols CheckForSemicolon(); CheckForClosingBrace(); }
protected override void UpdateMatrix() { WorldMatrix = ModelMatrix * this.GetTransformMatrix(); }
public override bool Draw3D(RenderContext11 renderContext, float opacity, Tile parent) { InViewFrustum = true; RenderedGeneration = CurrentRenderGeneration; if (!ReadyToRender) { TileCache.AddTileToQueue(this); return(false); } InViewFrustum = true; if (starVertexBuffer == null) { starProfile = Texture11.FromBitmap(Properties.Resources.StarProfile); int count = stars.Count; int index = 0; starCount = count; starVertexBuffer = new PositionColorSizeVertexBuffer11(count, RenderContext11.PrepDevice); PositionColorSize[] points = (PositionColorSize[])starVertexBuffer.Lock(0, 0); // Lock the buffer (which will return our structs) foreach (Star star in stars) { Vector3d pos = Coordinates.RADecTo3d(star.RA + 12, star.Dec, 1f); points[index].Position = pos.Vector3; points[index].Color = star.Col; double radDec = (.5) / Math.Pow(1.6, star.Magnitude); points[index].size = (float)radDec; index++; } starVertexBuffer.Unlock(); } renderContext.SetVertexBuffer(starVertexBuffer); renderContext.BlendMode = BlendMode.Additive; renderContext.DepthStencilMode = DepthStencilMode.Off; renderContext.setRasterizerState(TriangleCullMode.Off); SharpDX.Matrix mvp = (renderContext.World * renderContext.View * renderContext.Projection).Matrix11; mvp.Transpose(); PointSpriteShader11.WVPMatrix = mvp; PointSpriteShader11.Color = SharpDX.Color.White; float adjustedScale = (float)(1 / (Earth3d.MainWindow.ZoomFactor / 360)); PointSpriteShader11.ViewportScale = new SharpDX.Vector2((2.0f / renderContext.ViewPort.Width) * adjustedScale, (2.0f / renderContext.ViewPort.Height) * adjustedScale); PointSpriteShader11.PointScaleFactors = new SharpDX.Vector3(0.0f, 0.0f, 10000.0f); PointSpriteShader11.Use(renderContext.Device.ImmediateContext); renderContext.Device.ImmediateContext.PixelShader.SetShaderResource(0, starProfile.ResourceView); renderContext.devContext.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.PointList; renderContext.devContext.Draw(starCount, 0); renderContext.Device.ImmediateContext.GeometryShader.Set(null); // Reset blend mode so we don't mess up subsequent sky layer rendering renderContext.BlendMode = BlendMode.Alpha; return(true); }
public static Vector3 ScreenRelToWorld(Vector2 screenCoordsRel) { SharpDX.Matrix camMat = Util.GetCameraMatrix(); var screenPointVector = new SharpDX.Matrix(screenCoordsRel.X, 0, 0, 0, screenCoordsRel.Y, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0); var epsilon = 0.00001; if (Math.Abs(camMat.Determinant()) > epsilon) { var camMatInvert = camMat; camMatInvert.Invert(); var worldPointVector = camMatInvert * screenPointVector; var result = new Vector3(worldPointVector.M11, worldPointVector.M21, worldPointVector.M31); //UI.ShowSubtitle("Point: " + Math.Round(result.X, 1) + " | " + Math.Round(result.Y, 1) + " | " + Math.Round(result.Z, 1)); return result; } return new Vector3(0,0,0); }