• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Matrix4类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Matrix4的典型用法代码示例。如果您正苦于以下问题:C# Matrix4类的具体用法?C# Matrix4怎么用?C# Matrix4使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Matrix4类属于命名空间,在下文中一共展示了Matrix4类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: UnProject

        public static Vector4 UnProject(ref Matrix4 projection, Matrix4 view, Size viewport, MouseDevice mouse)
        {
            Vector4 vec;

            if (mouse.X > 0)
            {
                vec = new Vector4();
            }
            vec.X = 2.0f * mouse.X / (float)viewport.Width -1;
            vec.Y = -(2.0f * mouse.Y / (float)viewport.Height -1);
            vec.Z = 0;
            vec.W = 1.0f;

            Matrix4 viewInv = Matrix4.Invert(view);
            Matrix4 projInv = Matrix4.Invert(projection);

            Vector4.Transform(ref vec, ref projInv, out vec);
            Vector4.Transform(ref vec, ref viewInv, out vec);

            if (vec.W > float.Epsilon || vec.W < float.Epsilon)
            {
                vec.X /= vec.W;
                vec.Y /= vec.W;
                vec.Z /= vec.W;
            }

            return (vec);
        }
开发者ID:JIy3AHKO,项目名称:PubloG,代码行数:28,代码来源:MathHelper.cs


示例2: ColorScale

        public ColorScale(float min, float max, int width, int height)
        {
            this.width = width;
            this.height = height;
            this.min = min;
            this.max = max;
            length = 400.0f;
            barHeight = 25.0f;
            bottom = -height / 2.0f + 30.0f;
            left = -length / 2.0f;
            NumOfVertices = 0;
            cm = new Dictionary<float, Vector3>();
            popis_txt = new Text2D(width,height);
            popis_dic = new Dictionary<string, Vector4>();

            VAO = new int[1];
            VBO = new int[2];
            projectionMatrix = Matrix4.Identity;
            modelViewMatrix = Matrix4.Identity;

            VertexShader = new Shaders.Shader();
            FragmentShader = new Shaders.Shader();
            spMain = new Shaders.ShaderProgram();

            SetColorScale();
            SetText();
            Init();
        }
开发者ID:xmatakt,项目名称:bakalarka,代码行数:28,代码来源:ColorScale.cs


示例3: Mult

 /// 行列との掛け算
 public static Vector4 Mult( ref Vector4 pos, Matrix4 mtx )
 {
     calPos4.X = (mtx.M11 * pos.X) + (mtx.M21 * pos.Y) + ( mtx.M31 * pos.Z ) + ( mtx.M41 * pos.W );
     calPos4.Y = (mtx.M12 * pos.X) + (mtx.M22 * pos.Y) + ( mtx.M32 * pos.Z ) + ( mtx.M42 * pos.W );
     calPos4.Z = (mtx.M13 * pos.X) + (mtx.M23 * pos.Y) + ( mtx.M33 * pos.Z ) + ( mtx.M43 * pos.W );
     return calPos4;
 }
开发者ID:hatano0x06,项目名称:Coroppoxus,代码行数:8,代码来源:VectorUtil.cs


示例4: UnProject

        // UnProject takes a window-local mouse-coordinate, and a Z-coordinate depth [0,1] and
        // unprojects it, returning the point in world space. To get a ray, UnProject the
        // mouse coordinates at two different z-values.
        //
        // http://www.opentk.com/node/1276#comment-13029
        public static Vector3 UnProject(
			ref Matrix4 projection, 
			Matrix4 view, 
			System.Drawing.Size viewport, 
			Vector3 mouse)
        {
            Vector4 vec;

            vec.X = 2.0f * mouse.X / (float)viewport.Width - 1;
            vec.Y = -(2.0f * mouse.Y / (float)viewport.Height - 1);
            vec.Z = mouse.Z;
            vec.W = 1.0f;

            Matrix4 viewInv = Matrix4.Invert(view);
            Matrix4 projInv = Matrix4.Invert(projection);

            Vector4.Transform(ref vec, ref projInv, out vec);
            Vector4.Transform(ref vec, ref viewInv, out vec);

            if (vec.W > float.Epsilon || vec.W < float.Epsilon)
            {
                vec.X /= vec.W;
                vec.Y /= vec.W;
                vec.Z /= vec.W;
            }

            return new Vector3(vec.X,vec.Y,vec.Z);
        }
开发者ID:EMAGStefanMueller,项目名称:SimpleScene,代码行数:33,代码来源:OpenTKHelper.cs


示例5: ApplyProjectionMatrix

 public virtual void ApplyProjectionMatrix(ref Matrix4 pickMatrix)
 {
     CalculateProjectionMatrix();
     Matrix4 result = ProjectionMatrix * pickMatrix;
     GL.MatrixMode(MatrixMode.PROJECTION);
     GL.LoadMatrix(ref result);
 }
开发者ID:petya2164,项目名称:ZsharpGameEditor,代码行数:7,代码来源:Camera.cs


示例6: SetWorldTransform

 public unsafe static void SetWorldTransform(this MotionState obj, ref Matrix4 transform)
 {
     fixed (Matrix4* value = &transform)
     {
         obj.SetWorldTransform(ref *(Matrix*)value);
     }
 }
开发者ID:sinkingsugar,项目名称:BulletSharpPInvoke,代码行数:7,代码来源:MotionStateExtensions.cs


示例7: ColorBox

        /// <summary>
        /// position is top left of box.
        /// </summary>
        /// <param name="position"></param>
        /// <param name="size"></param>
        /// <param name="color"></param>
        public ColorBox(Vector2 position, Vector2 size, Color4 color)
        {
            this.position = position;
            this.size = size;
            model = Matrix4.CreateTranslation(position.X, position.Y, 0);
            Color = color;

            float[] vertices = new float[]
            {
                0, 0,
                0, size.Y,
                size.X, 0,
                size.X, size.Y
            };

            uint[] indices = new uint[]
            {
                0, 1, 2, 3
            };

            VBO vert = new VBO(), ind = new VBO();
            vert.SetData(ref vertices, BufferUsageHint.StaticDraw);
            ind.SetData(ref indices, BufferUsageHint.StaticDraw);

            bufSet = new BufferSet();
            bufSet.VertexBuffer = vert;
            bufSet.IndexBuffer = ind;
            bufSet.VertexSize = 2;
            bufSet.DrawMode = BeginMode.TriangleStrip;
            bufSet.SetDrawState(DrawStates.Vertex);
        }
开发者ID:Robmaister,项目名称:RoversSpirit,代码行数:37,代码来源:ColorBox.cs


示例8: AddCube

        public void AddCube(Matrix4 transform)
        {
            // Create VAO
            var vao = GL.GenVertexArray();
            GL.BindVertexArray(vao);

            // Create new buffer
            var buffer = GL.GenBuffer();
            GL.BindBuffer(BufferTarget.ArrayBuffer, buffer);
            float[] vertices =
            {
                -1f, -1f, -1f, 1f, -1f, -1f, -1f, -1f, 1f, -1f, -1f, 1f, 1f, -1f, -1f, 1f, -1f, 1f, //Front face
                1f, 1f, -1f, -1f, 1f, -1f, -1f, 1f, 1f, 1f, 1f, -1f, -1f, 1f, 1f, 1f, 1f, 1f, //Back face
                1f, -1f, -1f, 1f, 1f, -1f, 1f, -1f, 1f, 1f, -1f, 1f, 1f, 1f, -1f, 1f, 1f, 1f, //Right face
                -1f, 1f, -1f, -1f, -1f, -1f, -1f, -1f, 1f, -1f, 1f, -1f, -1f, -1f, 1f, -1f, 1f, 1f, //Left face
                -1f, -1f, 1f, 1f, -1f, 1f, -1f, 1f, 1f, -1f, 1f, 1f, 1f, -1f, 1f, 1f, 1f, 1f, //Top face
                1f, -1f, -1f, -1f, -1f, -1f, -1f, 1f, -1f, 1f, -1f, -1f, -1f, 1f, -1f, 1f, 1f, -1f //Bottom face
            };
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(sizeof(float) * vertices.Length), vertices, BufferUsageHint.StaticDraw);

            var posAttribute = GL.GetAttribLocation(shaderProgram, "aVertexPos");
            GL.EnableVertexAttribArray(posAttribute);
            GL.VertexAttribPointer(posAttribute, 3, VertexAttribPointerType.Float, false, Vector3.SizeInBytes, 0);

            GL.BindVertexArray(0);

            objects.Add(new DebugObject(vao, vertices.Length / 3, transform));
        }
开发者ID:SteamDatabase,项目名称:ValveResourceFormat,代码行数:28,代码来源:DebugUtil.cs


示例9: SpriteRenderer

        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="graphics"></param>
        /// <param name="maxSprites">The maximum number of sprites which can be batched.</param>
        public SpriteRenderer(GraphicsContext graphics, int maxSprites)
        {
            if (graphics == null)
                throw new ArgumentNullException("graphics");

            if (maxSprites <= 0)
                throw new ArgumentOutOfRangeException("maxSprites", "MaxSprites must be >= 1.");

            this.graphics = graphics;

            this.vertices = new Vertex[maxSprites * 4];

            this.vertexBuffer = new DynamicVertexBuffer<Vertex>(this.graphics);

            ushort[] indices = new ushort[1024 * 6];
            for (ushort i = 0, vertex = 0; i < indices.Length; i += 6, vertex += 4)
            {
                indices[i] = vertex;
                indices[i + 1] = (ushort)(vertex + 1);
                indices[i + 2] = (ushort)(vertex + 3);
                indices[i + 3] = (ushort)(vertex + 1);
                indices[i + 4] = (ushort)(vertex + 2);
                indices[i + 5] = (ushort)(vertex + 3);
            }

            this.indexBuffer = new StaticIndexBuffer<ushort>(this.graphics, indices);

            this.transform = new Matrix4()
            {
                M33 = 1f,
                M44 = 1f,
                M41 = -1f,
                M42 = 1f
            };
        }
开发者ID:smack0007,项目名称:Samurai,代码行数:40,代码来源:SpriteRenderer.cs


示例10: GetCurrentOrthogProjection

        public static void GetCurrentOrthogProjection(out bool isOrthog, out float left, out float right, out float bottom, out float top)
        {
            Matrix4 matrix = new Matrix4();
            GL.GetFloat(GetPName.ProjectionMatrix, out matrix.Row0.X);

			Helper.IsMatrixOrthogonal (out isOrthog, out left, out right, out bottom, out top, matrix);
        }
开发者ID:tgsstdio,项目名称:BirdNest.QuickFont,代码行数:7,代码来源:ProjectionStack.cs


示例11: UnprojectPoint

 public static Vector2 UnprojectPoint(Vector2 point, int screenWidth, int screenHeight, Matrix4 invProjection)
 {
     var x = (point.X * 2.0f / screenWidth) - 1.0f;
     var y = 1.0f - (point.Y * 2.0f / screenHeight);
     var p = new Vector3(x, y, -1.0f);
     return Vector3.Transform(p, invProjection).Xy;
 }
开发者ID:reward-hunters,项目名称:PrintAhead,代码行数:7,代码来源:SliceController.cs


示例12: Render

        public void Render(GameClient gameClient, RenderInfo renderInfo)
        {
            _currentFrameTime = GameTime.Now();

            GL.ClearColor(0.5f, 0.6f, 0.9f, 1f);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            GL.Enable(EnableCap.DepthTest);
            GL.Enable(EnableCap.CullFace);

            var offset = gameClient.PositionData.Placement.Pos - EntityPos.Origin;
            SetProjectionMatrix(renderInfo);

            _modelViewMatrix = Matrix4.Identity
                * Matrix4.CreateTranslation((float)-offset.X, (float)-offset.Y - gameClient.PhysicsValues.PlayerEyeHeight, (float)-offset.Z)
                * Matrix4.CreateRotationY((float)-gameClient.PositionData.Placement.Orientation.Horizontal)
                * Matrix4.CreateRotationX((float)gameClient.PositionData.Placement.Orientation.Vertical);

            _textureAtlas.Bind();

            RenderHighlightedFace(gameClient);

            RenderBlocks(gameClient);

            RenderEntities(gameClient);

            _outlineRenderer.RenderOutlines(renderInfo);
        }
开发者ID:AndiAngerer,项目名称:cubehack,代码行数:27,代码来源:WorldRenderer.cs


示例13: LookTrgVec

            /// 視線方向を向く(upベクトルがY軸プラス方向に固定版)
            public static void LookTrgVec( ref Matrix4 mtx, Vector3 lookVec )
            {
                Vector3 upVec = new Vector3( 0.0f, 1.0f, 0.0f );

                if( lookVec.X == 0.0f && lookVec.Z == 0.0f){
                lookVec.Z = 1.0f;
                }
                // Z軸のセット
                lookVec = lookVec.Normalize();
                mtx.M31 = lookVec.X;
                mtx.M32 = lookVec.Y;
                mtx.M33 = lookVec.Z;
                mtx.M34 = 0;

                // X軸のセット
                Vector3 calVecX = Common.VectorUtil.Cross2( upVec, lookVec );
                calVecX = calVecX.Normalize();
                mtx.M11 = calVecX.X;
                mtx.M12 = calVecX.Y;
                mtx.M13 = calVecX.Z;
                mtx.M14 = 0;

                // Y軸のセット
                Vector3 calVecY = VectorUtil.Cross2( lookVec, calVecX );
                calVecY = calVecY.Normalize();
                mtx.M21 = calVecY.X;
                mtx.M22 = calVecY.Y;
                mtx.M23 = calVecY.Z;
                mtx.M24 = 0;
            }
开发者ID:hatano0x06,项目名称:Coroppoxus,代码行数:31,代码来源:MatrixUtil.cs


示例14: SetTranslate

 /// 平行移動の代入
 public static void SetTranslate( ref Matrix4 mtx, Vector3 pos )
 {
     mtx.M41 = pos.X;
     mtx.M42 = pos.Y;
     mtx.M43 = pos.Z;
     mtx.M44 = 1.0f;
 }
开发者ID:hatano0x06,项目名称:Coroppoxus,代码行数:8,代码来源:MatrixUtil.cs


示例15: CreateBillboard

        public static void CreateBillboard(ref Vector3 objectPosition, ref Vector3 cameraPosition,
            ref Vector3 cameraUpVector, Vector3 cameraForwardVector, out Matrix4 result)
        {
            Vector3 look = cameraPosition - objectPosition;
            look = look.Normalize();

            Vector3 right = cameraUpVector.Cross(look).Normalize();
            Vector3 up = look.Cross(right).Normalize();
            //Matrix4 mat = Matrix4.LookAt(cameraPosition, cameraForwardVector, cameraUpVector);
            //Vector3 right = new Vector3(mat.M11, mat.M21, mat.M31);
            //right = right.Normalize();

            //Vector3 up = new Vector3(mat.M12, mat.M22, mat.M32);
            //up = up.Normalize();

            result.M11 = right.X;
            result.M12 = right.Y;
            result.M13 = right.Z;
            result.M14 = 0;
            result.M21 = up.X;
            result.M22 = up.Y;
            result.M23 = up.Z;
            result.M24 = 0;
            result.M31 = look.X;
            result.M32 = look.Y;
            result.M33 = look.Z;
            result.M34 = 0;
            result.M41 = objectPosition.X;
            result.M42 = objectPosition.Y;
            result.M43 = objectPosition.Z;
            result.M44 = 1;
        }
开发者ID:himanshugoel2797,项目名称:Aperture3D-PSM,代码行数:32,代码来源:MatrixExtensions.cs


示例16: Render

        public void Render(TerrainTile tile, TerrainGlobal terrainGlobal, Matrix4 projection, Matrix4 view, Vector3 eyePos)
        {
            var boxparam = tile.GetBoxParam();

            Vector3 eyePosTileCoords = Vector4.Transform(new Vector4(eyePos, 0.0f), tile.InverseModelMatrix).Xyz;

            GL.Enable(EnableCap.CullFace);
            GL.CullFace(CullFaceMode.Front);  // we only want to render back-faces

            tile.HeightTexture.Bind(TextureUnit.Texture0);
            tile.ParamTexture.Bind(TextureUnit.Texture1);
            tile.NormalTexture.Bind(TextureUnit.Texture2);

            this.boundingBoxProgram
                .UseProgram()
                .SetUniform("projection_matrix", projection)
                .SetUniform("model_matrix", tile.ModelMatrix)
                .SetUniform("view_matrix", view)
                .SetUniform("heightTex", 0)
                .SetUniform("paramTex", 1)
                .SetUniform("normalTex", 2)
                .SetUniform("eyePos", eyePos)
                .SetUniform("nEyePos", eyePosTileCoords)
                .SetUniform("boxparam", boxparam);
            this.vertexVBO.Bind(this.boundingBoxProgram.VariableLocation("vertex"));
            this.boxcoordVBO.Bind(this.boundingBoxProgram.VariableLocation("in_boxcoord"));
            this.indexVBO.Bind();
            GL.DrawElements(BeginMode.Triangles, this.indexVBO.Length, DrawElementsType.UnsignedInt, 0);
            Sampler.Unbind(TextureUnit.Texture0);
        }
开发者ID:geofftnz,项目名称:snowscape,代码行数:30,代码来源:GenerationVisRaycastRenderer.cs


示例17: Camera3D

 public Camera3D()
 {
     Matrix = Matrix4.Identity;
     rotation = Matrix4.Identity;
     translation = Matrix4.Identity;
     scale = Matrix4.Identity;
 }
开发者ID:LukaHorvat,项目名称:Electric,代码行数:7,代码来源:Camera3D.cs


示例18: Transform

 public Transform()
 {
     rotation = Quaternion.Identity;
     matrix = Matrix4.Identity;
     position = Vector3.Zero;
     scale = Vector3.One;
 }
开发者ID:gitter-badger,项目名称:Flare.Framework,代码行数:7,代码来源:Transform.cs


示例19: ReadMatrix4

 public static void ReadMatrix4(this BinaryReader reader, ref Matrix4 matrix)
 {
     ReadVector4(reader, ref matrix.Row0);
     ReadVector4(reader, ref matrix.Row1);
     ReadVector4(reader, ref matrix.Row2);
     ReadVector4(reader, ref matrix.Row3);
 }
开发者ID:johang88,项目名称:triton,代码行数:7,代码来源:BinaryReaderExtensions.cs


示例20: viewportSize

 public void viewportSize(int viewportWidth, int viewportHeight)
 {
     this.Width = viewportWidth;
     this.Height = viewportHeight;
     float aspectRatio = Width / (float)Height;
     projectionMatrix = Matrix4.CreatePerspectiveFieldOfView(MathHelper.PiOver4, aspectRatio, 1.0f, 4096.0f);
 }
开发者ID:Ser0ja,项目名称:WoWFormatTest,代码行数:7,代码来源:OldCamera.cs



注:本文中的Matrix4类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Matrix44类代码示例发布时间:2022-05-24
下一篇:
C# Matrix3x3类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap