Esempio n. 1
0
        public void Animate()
        {
            Vector2 cellSize = new Vector2(aSize, aSize);
            Vector2 halfCell = cellSize * 0.5f;
            Vector2 origo    = new Vector2(Rect.Min.X, Rect.Min.Y) + halfCell;
            float   scale    = (aSize - 10.0f) / 2.0f;

            float   t      = 0.1f * Time.Now;
            float   h      = t - (float)System.Math.Floor(t);
            float   angle  = (h - 0.25f) * 2.0f * (float)System.Math.PI;
            Vector3 center = new Vector3(origo, 0.0f);

            disc.Frame.LocalToParent.Set(
                Matrix4.CreateTranslation(center.X, center.Y, center.Z)
                * Matrix4.CreateScale(scale)
                * Matrix4.CreateRotation(angle, -Vector3.UnitZ)
                );
            triangle.Frame.LocalToParent.Set(
                Matrix4.CreateTranslation(center.X, center.Y, center.Z)
                * Matrix4.CreateScale(scale)
                * Matrix4.CreateRotation(0.5f * (float)System.Math.PI, Vector3.UnitZ)
                );

            hsv.Floats("t").Set(h);
            hsv.Sync();
        }
Esempio n. 2
0
        public void UpdateOncePerFrame()
        {
            if (frame == null)
            {
                return;
            }
            float phase = Time.Now / cycleTime;
            float angle = maxAngle * (float)System.Math.Sin(phase);

            Matrix4.CreateRotation(angle, axis, out rotationMatrix);

            Matrix4 localToParent = rotationMatrix;
            Matrix4 parentToLocal;

            Matrix4.Transpose(localToParent, out parentToLocal);


            /*  Put translation to column 3  */
            localToParent._03 = positionInParent.X;
            localToParent._13 = positionInParent.Y;
            localToParent._23 = positionInParent.Z;
            localToParent._33 = 1.0f;

            /*  Put inverse translation to column 3 */
            parentToLocal._03 = parentToLocal._00 * -positionInParent.X + parentToLocal._01 * -positionInParent.Y + parentToLocal._02 * -positionInParent.Z;
            parentToLocal._13 = parentToLocal._10 * -positionInParent.X + parentToLocal._11 * -positionInParent.Y + parentToLocal._12 * -positionInParent.Z;
            parentToLocal._23 = parentToLocal._20 * -positionInParent.X + parentToLocal._21 * -positionInParent.Y + parentToLocal._22 * -positionInParent.Z;
            parentToLocal._33 = 1.0f;

            Frame.LocalToParent.Set(localToParent, parentToLocal);
        }
Esempio n. 3
0
        private void Matrix4MultiplicationTest()
        {
            Setup("Matrix Multiplication");

            Matrix4 m1 = Matrix4.CreateTranslation(new Vector3(-10.4f, 23.2f, 0.12f));
            Matrix4 m2 = Matrix4.CreateRotation(Quaternion.CreateFromEuler(1.2f, 0.1f, -2.0f));
            Matrix4 m3 = Matrix4.CreateScale(new Vector3(1.2f, -4.0f, 2.3f));

            sw.Reset();
            sw.Start();
            for (int i = 0; i < iterations; ++i)
            {
                Matrix4 mat1 = m2 * m3;
                Matrix4 mat2 = m1 * mat1;
            }
            sw.Stop();
            PrintResults("Internal Call (C++)");


            sw.Reset();
            sw.Start();
            for (int i = 0; i < iterations; ++i)
            {
                Matrix4 mat1 = Matrix4_Multiply(m2, m3);
                Matrix4 mat2 = Matrix4_Multiply(m1, mat1);
            }
            sw.Stop();
            PrintResults("Managed Code (C#)");
        }
        public void Render(Matrix4 cameraTransform, Group renderGroup)
        {
            Matrix4 cameraRotation = cameraTransform;

            cameraRotation._03    = 0.0f;
            cameraRotation._13    = 0.0f;
            cameraRotation._23    = 0.0f;
            cameraRotation._33    = 1.0f;
            cameraRotation        = cameraRotation * Matrix4.CreateRotation((float)Math.PI, new Vector3(0.0f, 1.0f, 0.0f));
            renderer.CurrentGroup = renderGroup;

            // \todo Use a renderstate to control this
            GL.Disable(EnableCap.PolygonOffsetFill);

            Vector3 positionInWorld = cameraTransform.TransformPoint(new Vector3(0.0f, 0.0f, 0.0f));

            GL.ClearColor(1.0f, 1.0f, 1.0f, 1.0f);

            float sum = 0.0f;

            Render(HemicubeFramebuffer.PosXNegX, HemicubeOrientation.PosX, cameraRotation, positionInWorld);
            Render(HemicubeFramebuffer.PosXNegX, HemicubeOrientation.NegX, cameraRotation, positionInWorld);
            sum += ReadRedAverage(HemicubeFramebuffer.PosXNegX);
            Render(HemicubeFramebuffer.PosYNegY, HemicubeOrientation.PosY, cameraRotation, positionInWorld);
            Render(HemicubeFramebuffer.PosYNegY, HemicubeOrientation.NegY, cameraRotation, positionInWorld);
            sum += ReadRedAverage(HemicubeFramebuffer.PosYNegY);
            Render(HemicubeFramebuffer.NegZ, HemicubeOrientation.NegZ, cameraRotation, positionInWorld);
            sum += ReadRedAverage(HemicubeFramebuffer.NegZ);

            Average = sum * (1.0f / 3.0f);
        }
Esempio n. 5
0
        public void Animate()
        {
            Vector2 cellSize = new Vector2(brushSize, brushSize);
            Vector2 halfCell = cellSize * 0.5f;
            Vector2 origo    = new Vector2(Rect.Min.X, Rect.Min.Y) + halfCell;
            float   scale    = (brushSize - 10.0f) / 2.0f;

            Vector3      brushCenter = new Vector3(origo, 0.0f);
            List <Brush> brushes     = brushManager.Lists["platonic"];
            int          i           = 0;

            foreach (Brush brush in brushes)
            {
                //  Bypassing parent hierarchy to avoid need to update
                brush.Model.Frame.LocalToWorld.Set(
                    Matrix4.CreateTranslation(brushCenter.X, brushCenter.Y, brushCenter.Z)
                    * Matrix4.CreateScale(scale / brush.BoundingBox.HalfSize.MaxAxis.Length /* bounding sphere Radius */)
                    * Matrix4.CreateRotation((float)Math.PI * 0.1f, Vector3.UnitX)
                    * Matrix4.CreateRotation(Time.Now, Vector3.UnitY)
                    );

                rects[i].Min = brushCenter.Xy - halfCell;
                rects[i].Max = brushCenter.Xy + halfCell;

                // Advance to next cell slot
                brushCenter.X += cellSize.X;
                ++i;
                if (brushCenter.X + halfCell.X > Rect.Max.X)
                {
                    brushCenter.X  = origo.X;
                    brushCenter.Y += cellSize.Y;
                }
            }
        }
            public TreeTemplate(
                int sliceCount,
                int stackDivision,
                int coneCount,
                float height,
                float radius,
                float radAdd
                )
            {
                var          attributePosition = new Attribute(VertexUsage.Position, VertexAttribPointerType.Float, 0, 3);
                var          attributeNormal   = new Attribute(VertexUsage.Normal, VertexAttribPointerType.Float, 0, 3); /*  content normals     */
                VertexFormat vertexFormat      = new VertexFormat();

                vertexFormat.Add(attributePosition);
                vertexFormat.Add(attributeNormal);

                this.sliceCount    = sliceCount;
                this.stackDivision = stackDivision;
                this.coneCount     = coneCount;
                this.height        = height;
                this.radius        = radius;
                this.radAdd        = radAdd;
                float   coneHeight = height / (float)coneCount;
                Matrix4 rotZ       = Matrix4.CreateRotation(
                    RenderStack.Math.Conversions.DegreesToRadians(90.0f),
                    Vector3.UnitZ
                    );
                float    cylHeight        = coneHeight;
                float    cylRadius        = height / 20.0f;
                Geometry cylinderGeometry = new RenderStack.Geometry.Shapes.Cylinder(-cylHeight, cylHeight, cylRadius, sliceCount);

                cylinderGeometry.Transform(rotZ);
                GeometryMesh cylinderMesh  = new GeometryMesh(cylinderGeometry, NormalStyle.CornerNormals, vertexFormat);
                Shape        cylinderShape = new CylinderShape(cylHeight, cylRadius);

                cylinderMesh.GetMesh.Name = "cylinder";
                meshes.Add(cylinderMesh);
                shapes.Add(cylinderShape);
                for (int c = 0; c < coneCount; c++)
                {
                    float    topRadius      = (coneCount - 1 - c) * radius / (float)coneCount;
                    float    bottomRadius   = topRadius + radAdd;
                    float    R              = bottomRadius;
                    float    r              = topRadius;
                    float    fullConeHeight = (R * coneHeight) / (R - r);
                    float    minX           = -fullConeHeight / 3.0f;
                    float    maxX           = 2.0f * fullConeHeight / 3.0f;
                    float    offset         = -minX;
                    Geometry coneGeometry   = new RenderStack.Geometry.Shapes.Cone(minX, maxX, bottomRadius, 0.0f, true, true, sliceCount, stackDivision);
                    coneGeometry.Transform(rotZ);
                    GeometryMesh coneMesh  = new GeometryMesh(coneGeometry, NormalStyle.CornerNormals, vertexFormat);
                    Shape        coneShape = new ConeShape(fullConeHeight, R);
                    coneMesh.GetMesh.Name = "cone" + c.ToString();
                    meshes.Add(coneMesh);
                    shapes.Add(coneShape);
                }
            }
    private void OnDrawGizmos()
    {
        Vector3 pos   = new Vector3(0f, 0f, 0f);
        float   hSize = BoxSize / 2;

        Vector3[] boxVertecis = new Vector3[]
        {
            new Vector3(pos.x - hSize, pos.y - hSize, pos.z - hSize),
            new Vector3(pos.x + hSize, pos.y - hSize, pos.z - hSize),
            new Vector3(pos.x + hSize, pos.y + hSize, pos.z - hSize),
            new Vector3(pos.x - hSize, pos.y + hSize, pos.z - hSize),

            new Vector3(pos.x - hSize, pos.y - hSize, pos.z + hSize),
            new Vector3(pos.x + hSize, pos.y - hSize, pos.z + hSize),
            new Vector3(pos.x + hSize, pos.y + hSize, pos.z + hSize),
            new Vector3(pos.x - hSize, pos.y + hSize, pos.z + hSize),
        };

        Matrix4 sm = Matrix4.CreateScale(Scale.x, Scale.y, Scale.z);
        Matrix4 rm = Matrix4.CreateRotation(RotationX * Mathf.Deg2Rad, RotationY * Mathf.Deg2Rad, RotationZ * Mathf.Deg2Rad);
        Matrix4 tm = Matrix4.CreateTranslation(Position.position.x, Position.position.y, Position.position.z);

        Matrix4 tsrm  = tm * rm * sm;   // 변환 행렬의 적용 순서 반대로 곱해준다.
        Matrix4 tsrim = tsrm.Inverse(); // 역행렬


        // multifly matrix
        for (int i = 0; i < boxVertecis.Length; i++)
        {
            boxVertecis[i] = tsrm * boxVertecis[i];
        }

        // draw vertecis
        Color[] colors = new Color[] { Color.white, Color.yellow, Color.blue, Color.cyan };
        for (int i = 0; i < boxVertecis.Length; i++)
        {
            Color color = colors[(uint)i / 2];
            Gizmos.color = color;
            Gizmos.DrawWireSphere(boxVertecis[i], 0.1f);
        }

        // multifly matrix
        for (int i = 0; i < boxVertecis.Length; i++)
        {
            // 역행렬 곱해서 원래 좌표계로 돌림
            boxVertecis[i] = tsrim * boxVertecis[i];
        }

        // draw vertecis
        for (int i = 0; i < boxVertecis.Length; i++)
        {
            Color color = colors[(uint)i / 2];
            Gizmos.color = color;
            Gizmos.DrawWireSphere(boxVertecis[i], 0.1f);
        }
    }
Esempio n. 8
0
        public void Update(float rot)
        {
            var   pos   = Matrix4.CreateTranslation(Position);
            float angle = 20.0f * i;

            var rotAxis = new Vector3(1.0f, 0.0f, 1.0f);

            rotAxis = rotAxis.Normalize();
            m_Model = Matrix4.CreateRotation(rotAxis, MathHelper.ToRads(rot)) * pos;
        }
Esempio n. 9
0
        public void Update(long elapsedMilliseconds)
        {
            rot += (float)(GameTime.ElapsedSeconds * 15.0f);
            var scalefactor = (float)(12.0f * Math.Sin(rot * 0.1f) * Math.Sin(rot * 0.1f) + 2);

            var rotAxis = new Vector3(0.0f, 1.0f, 0.0f);

            rotAxis = rotAxis.Normalize();
            var r = Matrix4.CreateRotation(rotAxis, MathHelper.ToRads(rot * 16));

            model = Matrix4.CreateScaling(new Vector3(scalefactor, scalefactor, scalefactor)) * r;
        }
        public Manipulator(ManipulatorManager manager)
        {
            this.manager = manager;

            Active     = false;
            ActiveAxis = Axis.None;

            var redMaterial   = manager.MaterialManager["ManipulatorRed"];
            var greenMaterial = manager.MaterialManager["ManipulatorGreen"];
            var blueMaterial  = manager.MaterialManager["ManipulatorBlue"];

            var renderer = manager.Renderer;

            float cylinderWidth = 0.02f;
            float coneStart     = 0.4f;
            float coneWidth     = 0.2f;
            float scale         = 0.15f;
            //float scale     = 1.0f;

            var axisCylinder = new GeometryMesh(
                new Cylinder(0.0, coneStart * scale, cylinderWidth * scale, 20),
                NormalStyle.CornerNormals
                );
            var axisCone = new GeometryMesh(
                new Cone(coneStart * scale, 1.0 * scale, coneWidth * scale, 0.0, true, false, 20, 4),
                NormalStyle.CornerNormals
                );

            Matrix4 translation = Matrix4.CreateTranslation(0.0f, 0.0f, 0.0f);
            Matrix4 toYAxis     = Matrix4.CreateRotation((float)Math.PI * 0.5f, new Vector3(0.0f, 0.0f, 1.0f));
            Matrix4 toZAxis     = Matrix4.CreateRotation(-(float)Math.PI * 0.5f, new Vector3(0.0f, 1.0f, 0.0f));

            XCylinder = new Model("X-Axis Cylinder", axisCylinder, redMaterial);
            XCone     = new Model("X-Axis Cone", axisCone, redMaterial);
            YCylinder = new Model("Y-Axis Cylinder", axisCylinder, greenMaterial, toYAxis);
            YCone     = new Model("Y-Axis Cone", axisCone, greenMaterial, toYAxis);
            ZCylinder = new Model("Z-Axis Cylinder", axisCylinder, blueMaterial, toZAxis);
            ZCone     = new Model("Z-Axis Cone", axisCone, blueMaterial, toZAxis);

            XCylinder.Frame.Parent = transform;
            XCone.Frame.Parent     = transform;
            YCylinder.Frame.Parent = transform;
            YCone.Frame.Parent     = transform;
            ZCylinder.Frame.Parent = transform;
            ZCone.Frame.Parent     = transform;

            manager.ManipulatorGroup.Add(XCylinder);
            manager.ManipulatorGroup.Add(XCone);
            manager.ManipulatorGroup.Add(YCylinder);
            manager.ManipulatorGroup.Add(YCone);
            manager.ManipulatorGroup.Add(ZCylinder);
            manager.ManipulatorGroup.Add(ZCone);
        }
Esempio n. 11
0
        public void GenerateTubeVerticesForCusp(Vector3 T1, Vector3 T2, float t0, float t1)
        {
            float tm = t0 + (t1 - t0) * 0.5f;

            Vector3 cross = Vector3.Cross(T1, T2);

            //  Special case: cross product is 0, there is no unique axis
            //  for rotation. Pick 'any' perpendicular vector.
            if (cross.LengthSquared < 0.001f)
            {
                cross = Vector3.Cross(T1, T1.MinAxis);
            }
            Vector3 axis  = Vector3.Normalize(cross);
            float   dot   = Vector3.Dot(T1, T2);
            float   theta = (float)Math.Acos(dot);
            Vector3 pos   = curve.PositionAt(tm);

            float qtStep = 1.0f / (float)8.0;

            for (float qt = 0.0f; qt <= 1.0f; qt += qtStep)
            {
                Matrix4 R = Matrix4.CreateRotation(qt * theta, axis);
                Vector3 T = R * T1;
                Vector3 B = Vector3.Normalize(Vector3.Cross(T, LastN));
                LastN = Vector3.Normalize(Vector3.Cross(B, T));

                ++TubeStackCount;
                for (int slice = 0; slice < tubeSliceCount; ++slice)
                {
                    float relPhi = (float)slice / (float)tubeSliceCount;
                    float phi    = (float)Math.PI * 2.0f * relPhi;
                    float sinPhi = (float)Math.Sin(phi);
                    float cosPhi = (float)Math.Cos(phi);

                    Vector3 v = pos;
                    Vector3 n = LastN * sinPhi + B * cosPhi;
                    v += n * TubeRadius;

                    float r, g, b;
                    RenderStack.Math.Conversions.HSVtoRGB(360.0f * tm, 1.0f, 1.0f, out r, out g, out b);

                    tubeVertexWriter.Set(tubePosition, v.X, v.Y, v.Z);
                    tubeVertexWriter.Set(tubeNormal, n.X, n.Y, n.Z);
                    tubeVertexWriter.Set(tubeTangent, T.X, T.Y, T.Z);
                    //tubeVertexWriter.Set(tubeTangent, B.X, B.Y, B.Z);
                    tubeVertexWriter.Set(tubeColor, r, g, b, 1.0f);
                    tubeVertexWriter.Set(tubeT, tm);
                    tubeVertexWriter.Set(tubeId, 0);
                    ++tubeVertexWriter.CurrentIndex;
                }
            }
        }
Esempio n. 12
0
        public static Matrix4 GetViewMatrix()
        {
            Matrix4 viewTranslation = Matrix4.Identity;
            Matrix4 viewRotation    = Matrix4.Identity;
            Matrix4 viewScale       = Matrix4.Identity;

            viewTranslation = Matrix4.CreateTranslation(new Vector3(-Camera.worldPosition.X, -Camera.worldPosition.Y, Camera.worldPosition.Z));
            viewRotation    = Matrix4.CreateRotation(new Vector3(0f, 1f, 0f), Camera.cameraYaw); // In radiant
            viewScale       = Matrix4.CreateScaling(new Vector3(1.0f, 1.0f, 1.0f));

            Matrix4 view = viewRotation * viewTranslation * viewScale;// RTS matrix -> scale, rotate then translate -> All applied in LOCAL Coordinates

            return(view);
        }
Esempio n. 13
0
        public void AddSimpleScene()
        {
            //  Shapes here have local 0,0,0 at center of mass
            Geometry     cubeGeometry = new RenderStack.Geometry.Shapes.Cube(1.0f, 1.0f, 1.0f);
            GeometryMesh cubeMesh     = new GeometryMesh(cubeGeometry, NormalStyle.PolygonNormals);

            GeometryMesh sphereMesh = new GeometryMesh(
                new RenderStack.Geometry.Shapes.Sphere(0.75, 20, 12),
                NormalStyle.CornerNormals
                );
            Geometry cylinderGeometry = new RenderStack.Geometry.Shapes.Cylinder(-0.5f, 0.5f, 0.5f, 24);

            cylinderGeometry.Transform(
                Matrix4.CreateRotation(
                    Conversions.DegreesToRadians(90.0f),
                    Vector3.UnitZ
                    )
                );
            GeometryMesh cylinderMesh = new GeometryMesh(cylinderGeometry, NormalStyle.CornerNormals);
            Geometry     coneGeometry = new RenderStack.Geometry.Shapes.Cone(-1.0f / 3.0f, 2.0f / 3.0f, 0.75f, 0.0f, true, false, 24, 10);

            coneGeometry.Transform(
                Matrix4.CreateRotation(
                    Conversions.DegreesToRadians(90.0f),
                    Vector3.UnitZ
                    )
                );
            GeometryMesh coneMesh = new GeometryMesh(coneGeometry, NormalStyle.CornerNormals);

            /*  Models  */
            float    gap     = 2.5f;
            Material pearl   = materialManager["pearl"];
            Material gold    = materialManager["gold"];
            Material red     = materialManager["red"];
            Material green   = materialManager["green"];
            Material cyan    = materialManager["cyan"];
            Material blue    = materialManager["blue"];
            Material magenta = materialManager["magenta"];
            Material pink    = materialManager["pink"];

            AddModel(new Model("cube", cubeMesh, pearl, -3.5f * gap, 0.5f, 0.0f));
            AddModel(new Model("box", cubeMesh, gold, -2.5f * gap, 0.5f, 0.0f));
            AddModel(new Model("sphere", sphereMesh, red, -1.5f * gap, 0.75f, 0.0f));
            AddModel(new Model("sphere", sphereMesh, green, -0.5f * gap, 0.75f, 0.0f));
            AddModel(new Model("cylinder", cylinderMesh, cyan, 0.5f * gap, 0.5f, 0.0f));
            AddModel(new Model("cylinder", cylinderMesh, blue, 1.5f * gap, 0.5f, 0.0f));
            AddModel(new Model("cone", coneMesh, magenta, 2.5f * gap, 1.0f / 3.0f, 0.0f));
            AddModel(new Model("cone", coneMesh, pink, 3.5f * gap, 1.0f / 3.0f, 0.0f));
        }
Esempio n. 14
0
 public void Draw(ShaderProgram program)
 {
     #region
     Gl.BindTexture(texture);
     program["model_matrix"].SetValue(Matrix4.CreateRotation(rotation, angle) *
                                      Matrix4.CreateScaling(scale) *
                                      Matrix4.CreateTranslation(position));
     Gl.BindBufferToShaderAttribute(vertex, program, "vertexPosition");
     Gl.BindBufferToShaderAttribute(uvs, program, "vertexUV");
     Gl.BindBuffer(elements);
     //Dibuja el cube
     Gl.DrawElements(BeginMode.Triangles, elements.Count,
                     DrawElementsType.UnsignedInt, IntPtr.Zero);
     #endregion
 }
Esempio n. 15
0
        public Matrix4 GetTRS()
        {
            Matrix4 modelTranslation = Matrix4.CreateTranslation(Position);
            Matrix4 modelRotationX   = Matrix4.CreateRotation(new Vector3(1.0f, 0.0f, 0.0f),
                                                              Mathf.ToRad(Rotation.X));
            Matrix4 modelRotationY = Matrix4.CreateRotation(new Vector3(0.0f, 1.0f, 0.0f),
                                                            Mathf.ToRad(Rotation.Y));
            Matrix4 modelRotationZ = Matrix4.CreateRotation(new Vector3(0.0f, 0.0f, 1.0f),
                                                            Mathf.ToRad(Rotation.Z));
            Matrix4 modelRotation = modelRotationX * modelRotationY * modelRotationZ;
            Matrix4 modelScale    = Matrix4.CreateScaling(Scale);
            Matrix4 model         = modelTranslation * modelRotation * modelScale;// Compose TRS matr

            return(model);
        }
        public void MakeNoiseScene()
        {
            Reset();

            float scale = 1.0f;

            AddFloor(30.0f * scale, 5, -0.5f);

            int      subdiv       = 3;
            Geometry coneGeometry = new RenderStack.Geometry.Shapes.Cone(
                -1.0f / 3.0f, 2.0f / 3.0f, 0.75f, 0.0f, true, false, 24 * subdiv, 10 * subdiv
                );

            coneGeometry.Transform(
                Matrix4.CreateRotation(
                    RenderStack.Math.Conversions.DegreesToRadians(90.0f),
                    Vector3.UnitZ
                    )
                );
            //coneGeometry = Mush(0.08f, coneGeometry);
            var coneMesh  = new GeometryMesh(coneGeometry, NormalStyle.CornerNormals);
            var coneShape = new ConeShape(1.0f, 0.75f);
            var gold      = materialManager["noisy"];
            var magenta   = materialManager["magenta"];

            userInterfaceManager.CurrentMaterial = "noisy";

            Geometry ellipsoidGeometry = new RenderStack.Geometry.Shapes.Ellipsoid(
                new Vector3(0.5f, 1.0f, 1.5f), 20, 12
                );

            var ellipsoidMesh  = new GeometryMesh(ellipsoidGeometry, NormalStyle.PointNormals);
            var ellipsoidShape = new EllipsoidShape(0.5f, 1.0f, 1.5f);

            for (float x = -4.0f; x <= 4.0f; x += 8.0f)
            {
                for (float z = -4.0f; z <= 4.0f; z += 8.0f)
                {
                    AddModel(new Model("cone", coneMesh, gold, x, 1.0f / 3.0f, z), coneShape).RigidBody.IsActive            = false;
                    AddModel(new Model("ellipsoid", ellipsoidMesh, magenta, x, 2.0f, z), ellipsoidShape).RigidBody.IsActive = false;
                }
            }

            AddCameras();
            AddCameraUserControls();
        }
        public void MakeTree(Vector3 pos, TreeTemplate template)
        {
            int      i          = 0;
            Material wood       = materialManager["wood"];
            Material leaves     = materialManager["leaves"];
            float    coneHeight = template.Height / (float)template.ConeCount;
            Matrix4  rotZ       = Matrix4.CreateRotation(
                RenderStack.Math.Conversions.DegreesToRadians(90.0f),
                Vector3.UnitZ
                );
            float        cylHeight     = coneHeight;
            float        cylRadius     = template.Height / 20.0f;
            GeometryMesh cylinderMesh  = template.Meshes[i];
            Shape        cylinderShape = template.Shapes[i];

            ++i;
            Model rootModel = new Model("TreeRoot", cylinderMesh, wood, pos.X, pos.Y + cylHeight / 2.0f, pos.Z);

            AddModel(rootModel, null);
            Model below      = rootModel;
            float prevOffset = cylHeight / 2.0f;

            for (int c = 0; c < template.ConeCount; c++)
            {
                float topRadius      = (template.ConeCount - 1 - c) * template.Radius / (float)template.ConeCount;
                float bottomRadius   = topRadius + template.RadAdd;
                float R              = bottomRadius;
                float r              = topRadius;
                float fullConeHeight = (R * coneHeight) / (R - r);
                float minX           = -fullConeHeight / 3.0f;
                //float maxX = 2.0f * fullConeHeight / 3.0f;
                float        offset    = -minX;
                GeometryMesh coneMesh  = template.Meshes[i];
                Shape        coneShape = template.Shapes[i];
                ++i;
                Model coneModel = new Model("TreeCone", coneMesh, leaves, 0.0f, prevOffset + offset, 0.0f);
                coneModel.Frame.Parent = below.Frame;
                AddModel(coneModel, null);
                Bender bender = new Bender(Vector3.UnitZ, 0.1f, 2.0f);
                bender.Frame = coneModel.Frame;
                Add(bender);
                below      = coneModel;
                prevOffset = offset;
            }
        }
        public void UpdateTransform()
        {
            if (physicsObject == null)
            {
                return;
            }
            //physicsObject.Frame.UpdateHierarchical();

            Matrix4 elevationMatrix = Matrix4.CreateRotation(elevation, Vector3.UnitX);

            headingMatrix  = Matrix4.CreateRotation(heading, Vector3.UnitY);
            rotationMatrix = headingMatrix * elevationMatrix;

            /*
             * physicsObject.RigidBody.IsActive = true;
             * physicsObject.RigidBody.Orientation = new Jitter.LinearMath.JMatrix(
             *  rotationMatrix._00, rotationMatrix._10, rotationMatrix._20,
             *  rotationMatrix._01, rotationMatrix._11, rotationMatrix._21,
             *  rotationMatrix._02, rotationMatrix._12, rotationMatrix._22
             * );
             */

            Matrix4 newLocalToWorld = physicsObject.Frame.LocalToWorld.Matrix;
            Matrix4 newWorldToLocal = physicsObject.Frame.LocalToWorld.InverseMatrix;

            newLocalToWorld._00 = rotationMatrix._00; newLocalToWorld._01 = rotationMatrix._01; newLocalToWorld._02 = rotationMatrix._02;
            newLocalToWorld._10 = rotationMatrix._10; newLocalToWorld._11 = rotationMatrix._11; newLocalToWorld._12 = rotationMatrix._12;
            newLocalToWorld._20 = rotationMatrix._20; newLocalToWorld._21 = rotationMatrix._21; newLocalToWorld._22 = rotationMatrix._22;

            if (physicsObject.Frame.Parent != null)
            {
                Matrix4 oldWorldToParent = physicsObject.Frame.Parent.LocalToWorld.InverseMatrix;
                Matrix4 newLocalToParent = oldWorldToParent * newLocalToWorld;
                physicsObject.Frame.LocalToParent.Set(newLocalToParent);
            }
            else
            {
                physicsObject.Frame.LocalToParent.Set(newLocalToWorld);
            }

            //  Also update local to world properly
            physicsObject.Frame.UpdateHierarchicalNoCache();
        }
Esempio n. 19
0
        public void FixedUpdate()
        {
            TranslateX.Update();
            TranslateY.Update();
            TranslateZ.Update();
            RotateX.Update();
            RotateY.Update();
            RotateZ.Update();

            if (TranslateX.CurrentValue != 0.0f)
            {
                /*  Right axis is column 0  */
                positionInParent += rotationMatrix.GetColumn3(0) * TranslateX.CurrentValue;
            }
            if (TranslateY.CurrentValue != 0.0f)
            {
                /*  Up axis is column 1  */
                positionInParent += rotationMatrix.GetColumn3(1) * TranslateY.CurrentValue;
            }
            if (translateZ.CurrentValue != 0.0f)
            {
                /*  View axis is column 2  */
                positionInParent += rotationMatrix.GetColumn3(2) * TranslateZ.CurrentValue;
            }
            if (RotateX.CurrentValue != 0.0f)
            {
                Matrix4 rotation = Matrix4.CreateRotation(RotateX.CurrentValue, rotationMatrix.GetColumn3(0));
                rotationMatrix = rotation * rotationMatrix;
            }
            if (RotateY.CurrentValue != 0.0f)
            {
                Matrix4 rotation = Matrix4.CreateRotation(RotateY.CurrentValue, rotationMatrix.GetColumn3(1));
                rotationMatrix = rotation * rotationMatrix;
            }
            if (RotateZ.CurrentValue != 0.0f)
            {
                Matrix4 rotation = Matrix4.CreateRotation(RotateZ.CurrentValue, rotationMatrix.GetColumn3(2));
                rotationMatrix = rotation * rotationMatrix;
            }
        }
        public void Update()
        {
            Matrix4 elevationMatrix = Matrix4.CreateRotation(elevation, Vector3.UnitX);

            headingMatrix  = Matrix4.CreateRotation(heading, Vector3.UnitY);
            rotationMatrix = headingMatrix * elevationMatrix;

            if (frame == null)
            {
                return;
            }

            Matrix4 localToParent = rotationMatrix;
            Matrix4 parentToLocal;

            Matrix4.Transpose(localToParent, out parentToLocal);

            // HACK
            if (positionInParent.Y < 0.03f)
            {
                positionInParent.Y = 0.03f;
            }

            /*  Put translation to column 3  */
            localToParent._03 = positionInParent.X;
            localToParent._13 = positionInParent.Y;
            localToParent._23 = positionInParent.Z;
            localToParent._33 = 1.0f;

            /*  Put inverse translation to column 3 */
            parentToLocal._03 = parentToLocal._00 * -positionInParent.X + parentToLocal._01 * -positionInParent.Y + parentToLocal._02 * -positionInParent.Z;
            parentToLocal._13 = parentToLocal._10 * -positionInParent.X + parentToLocal._11 * -positionInParent.Y + parentToLocal._12 * -positionInParent.Z;
            parentToLocal._23 = parentToLocal._20 * -positionInParent.X + parentToLocal._21 * -positionInParent.Y + parentToLocal._22 * -positionInParent.Z;
            parentToLocal._33 = 1.0f;

            Frame.LocalToParent.Set(localToParent, parentToLocal);
        }
Esempio n. 21
0
        int parse_rotate(string str)
        {
            double[] args = new double[3];
            int      na   = 0;
            int      len  = parse_transform_args(str, args, ref na);

            if (na == 1)
            {
                m_SVGPath.Transform = m_SVGPath.Transform.Multiply(Matrix4.CreateRotation(MathHelper.DegreesToRadians(args[0])), MatrixOrder.Append);
            }
            else if (na == 3)
            {
                Matrix4 t = Matrix4.CreateTranslation(-args[1], -args[2]);
                t.Rotate(args[0], MatrixOrder.Append);
                t.Translate(args[1], args[2], MatrixOrder.Append);
                m_SVGPath.Transform = m_SVGPath.Transform.Multiply(t, MatrixOrder.Append);
            }
            else
            {
                throw new SVGException("parse_rotate: Invalid number of arguments");
            }

            return(len);
        }
Esempio n. 22
0
 public void SetRotation(float angleRadians, Vector3 axis)
 {
     Matrix4.CreateRotation(angleRadians, axis, out matrix);
     Matrix4.CreateRotation(-angleRadians, axis, out inverseMatrix);
 }
Esempio n. 23
0
 public void Rotate(float radians)
 {
     _rotation *= Matrix4.CreateRotation(radians);
 }
Esempio n. 24
0
 public Matrix4 CreateAngleRotation()
 {
     return(Matrix4.CreateRotation(Utils.DegToRad(-VerticalAngle), Utils.DegToRad(-HorizontalAngle), 0));
 }
Esempio n. 25
0
        public void Render(Matrix4 cameraTransform, Group renderGroup)
        {
            Matrix4 cameraRotation = cameraTransform;

            cameraRotation._03 = 0.0f;
            cameraRotation._13 = 0.0f;
            cameraRotation._23 = 0.0f;
            cameraRotation._33 = 1.0f;
            cameraRotation     = cameraRotation * Matrix4.CreateRotation(
                (float)System.Math.PI,
                Vector3.UnitY
                );

            renderer.CurrentGroup       = renderGroup;
            renderer.Requested.Viewport = framebuffer;

            Vector3 positionInWorld = cameraTransform.TransformPoint(new Vector3(0.0f, 0.0f, 0.0f));

            for (int i = 0; i < 6; ++i)
            {
                framebuffer.AttachCubeFace(
                    FramebufferAttachment.ColorAttachment0,
                    TextureTarget.TextureCubeMapPositiveX + i,
                    0
                    );
                framebuffer.Begin();
                framebuffer.Check();

                Matrix4 localToWorld = cameraRotation * faceOrientation[i];
                localToWorld._03       = positionInWorld.X;
                localToWorld._13       = positionInWorld.Y;
                localToWorld._23       = positionInWorld.Z;
                camera[i].Frame.Parent = null;
                camera[i].Frame.LocalToParent.Set(localToWorld);
                camera[i].Frame.LocalToWorld.Set(localToWorld);
                renderer.Requested.Camera = camera[i];
                //camera[i].Frame.UpdateHierarchical(1);

                GL.Viewport(
                    (int)renderer.Requested.Viewport.X,
                    (int)renderer.Requested.Viewport.Y,
                    (int)renderer.Requested.Viewport.Width,
                    (int)renderer.Requested.Viewport.Height
                    );
                GL.ClearColor(1.0f, 1.0f, 1.0f, 1.0f);
                GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

                renderer.CurrentGroup       = renderGroup;
                renderer.Requested.MeshMode = MeshMode.PolygonFill;
                renderer.RenderGroup();//null, null, MeshMode.NotSet);

                framebuffer.End();
            }
            //framebuffer.UnbindTexture(FramebufferAttachment.ColorAttachment0);

            {
                GL.ActiveTexture(TextureUnit.Texture0);
                GL.BindTexture(TextureTarget.TextureCubeMap, Texture.TextureObject);
                GL.GenerateMipmap(GenerateMipmapTarget.TextureCubeMap);
                GL.BindTexture(TextureTarget.TextureCubeMap, 0);
            }
        }
Esempio n. 26
0
 public Matrix4 CreateTransformMatrix(bool overrideScale = false, Vector3 newScale = new Vector3())
 {
     return(Matrix4.CreateTranslation(Position) * Matrix4.CreateRotation(Rotation) * (Matrix4.CreateScale(overrideScale ? newScale : Scale)));
 }
Esempio n. 27
0
        protected override void OnInit()
        {
            base.OnInit();

            var rot = Matrix4.CreateRotationX(0) * Matrix4.CreateRotationY(0) * Matrix4.CreateRotationZ(90);

            Console.WriteLine(rot);
            Console.WriteLine(Matrix4.CreateRotation(new Angle(30f, 45f, 30f)).Rotation);

            Positions = new Vector3[Billboards];
            var rand = new Random();

            for (var i = 0; i < Billboards; i++)
            {
                Positions[i] = new Vector3(-200f + (float)rand.NextDouble() * 400f, -200f + (float)rand.NextDouble() * 400f, 0f);
            }

            Instances = VKBuffer.InstanceInfo <InstanceInfo>(Graphics, Billboards);
            Instances.Write(Positions);
            BViewProjection = VKBuffer.UniformBuffer <ViewProjection>(Graphics, 1);
            var testImg = Content.Get <Image>("Data/tex.png");

            using (var imgBuilder = new ImageBuilder(testImg))
            {
                var data = imgBuilder.GetData();
                for (var i = 0; i < data.Length; i += 4)
                {
                    data[i + 2] += 128;
                }
                imgBuilder.SetData(data);
                imgBuilder.Finish();
                TestTex = Texture2D.FromBitmap(Graphics, imgBuilder, new Rectangle[] { new Rectangle(Point.Empty, testImg.Size) });
            }

            Pipeline                  = new PipelineController(Graphics);
            Pipeline.DepthTest        = true;
            Pipeline.DepthWrite       = true;
            Pipeline.BlendMode        = BlendMode.Alpha;
            Pipeline.Instancing       = true;
            Pipeline.InstanceInfoType = typeof(InstanceInfo);
            Pipeline.Shaders          = new[] { "Data/billboard.vert.spv", "Data/billboard.frag.spv" };
            Pipeline.DescriptorItems  = new[] {
                DescriptorItem.UniformBuffer(DescriptorItem.ShaderType.Vertex, BViewProjection),
                DescriptorItem.CombinedImageSampler(DescriptorItem.ShaderType.Fragment, TestTex, DescriptorItem.SamplerFilter.Nearest, DescriptorItem.SamplerFilter.Nearest)
            };
            Pipeline.Build();

            /*var font = SpriteFont.FromSprites(
             *  Graphics, Content.Get<Texture2D>("Data/ascii.png"), new Vector2(10f, 18f), Vector2.Zero, new Vector2(16f, 16f), 256 / 16,
             *  " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
             * );*/
            var font = SpriteFont.FromFont(Graphics, "Arial", FontStyle.Regular, 20.0f, 20f, true, '\n', (char)127, 16);

            TextRenderer = new TextRenderer(Graphics, font, "Data/text.vert.spv", "Data/text.frag.spv", 128);
            TextRenderer.BuildPipeline();
            TextInstances = new[] { new TextRenderer.TextInstance(Vector2.Zero, Vector2.One, Color4.LightGray, 1, new Color4(0f, 0f, 0f, 1f), new Vector2(0f, 0f), Vector2.Zero, "N/A") };

            MeshRenderer = new MeshRenderer(Graphics, Content.Get <Texture2D>("Data/tex.png"), "Data/mesh.vert.spv", "Data/mesh.frag.spv", 32, 4);
            MeshRenderer.BuildPipeline();
            MeshRenderer.SetMeshInfo(
                new[] {
                MeshRenderer.CreateMeshInfo(
                    Mesh.FromPolygon(Graphics, new[]
                {
                    new Vertex(new Vector3(-180f, -90f, 0f), new Vector3(0f, 0f, 1f), new Vector2(0f, 0f), Color4.White),
                    new Vertex(new Vector3(0f, -180f, 0f), new Vector3(0f, 0f, 1f), new Vector2(0.5f, 0f), Color4.White),
                    new Vertex(new Vector3(180f, 0f, 0f), new Vector3(0f, 0f, 1f), new Vector2(1f, 0.2f), Color4.White),
                    new Vertex(new Vector3(0f, 120f, 0f), new Vector3(0f, 0f, 1f), new Vector2(0f, 1f), Color4.White),
                    new Vertex(new Vector3(-180f, 90f, 0f), new Vector3(0f, 0f, 1f), new Vector2(0.1f, 1f), Color4.White)
                }),
                    new Sprite(new Vector2(0f, 0f), new Vector2(64f, 64f)),
                    new Vector3(400f, 300f, 0f),
                    Vector3.One,
                    Matrix4.CreateRotationZ(0f),
                    Vector3.Zero
                    ),
                MeshRenderer.CreateMeshInfo(
                    new Mesh(
                        Graphics,
                        new Vertex[]
                {
                    new Vertex(new Vector3(-180f, -90f, 0f), new Vector3(0f, 0f, 1f), new Vector2(0f, 0f), Color4.White),
                    new Vertex(new Vector3(0f, -90f, 0f), new Vector3(0f, 0f, 1f), new Vector2(1f, 0f), Color4.White),
                    new Vertex(new Vector3(180f, 90f, 0f), new Vector3(0f, 0f, 1f), new Vector2(1f, 1f), Color4.White),
                    new Vertex(new Vector3(0f, 90f, 0f), new Vector3(0f, 0f, 1f), new Vector2(0f, 1f), Color4.White)
                },
                        new int[] { 0, 1, 2, 2, 3, 0 }
                        ),
                    new Sprite(new Vector2(0f, 0f), new Vector2(64f, 64f)),
                    new Vector3(580f, 300f, 0f),
                    Vector3.One,
                    Matrix4.CreateRotationZ(0f),
                    Vector3.Zero
                    )
            },
                2
                );

            ParticleRenderer = new ParticleRenderer(
                Graphics, Content.Get <Texture2D>("Data/fire.png"),
                new Sprite(Vector2.Zero, new Vector2(64f, 64f), new Vector2(64f, 64f)),
                "Data/particle.vert.spv", "Data/particle.frag.spv", 900000
                );
            ParticleRenderer.BlendMode = BlendMode.Add;
            ParticleRenderer.BuildPipeline();
        }
Esempio n. 28
0
 public void SetRotation(float radians)
 {
     _rotation = Matrix4.CreateRotation(radians);
 }
        public void MakeSimpleScene()
        {
            System.Console.WriteLine("MakeSimpleScene");
            int subdiv = 1;

            Reset();

            float scale = 1.0f;

            //sceneManager.AddFloor(22.0f * scale, 0, -1.0f);
            AddFloor(22.0f * scale, 5, -0.5f);

            /*  Renderable meshes  */
            Geometry cubeGeometry = new RenderStack.Geometry.Shapes.Cube(1.0f, 1.0f, 1.0f);

            //Geometry cubeGeometry = new RenderStack.Geometry.Shapes.Cube(Vector3.One, new IVector3(20, 20, 20), 1.0f);
            cubeGeometry = Mush(0.04f, cubeGeometry);

            /*cubeGeometry.BuildEdges();
            *  cubeGeometry = new SubdivideGeometryOperation(cubeGeometry).Destination;
            *  cubeGeometry = new SubdivideGeometryOperation(cubeGeometry).Destination;
            *  cubeGeometry = new SubdivideGeometryOperation(cubeGeometry).Destination;
            *  cubeGeometry = new CatmullClarkGeometryOperation(cubeGeometry).Destination;
            *  cubeGeometry.ComputePolygonCentroids();
            *  cubeGeometry.ComputePolygonNormals();
            *  cubeGeometry.ComputeCornerNormals(0.0f);
            *  cubeGeometry.BuildEdges();*/
            GeometryMesh cubeMesh = new GeometryMesh(cubeGeometry, NormalStyle.PolygonNormals);

#if OPENRL
            Geometry geodesatedBoxGeometry = new RenderStack.Geometry.Shapes.Cube(
                new Vector3(1.0f, 1.0f, 1.0f), new IVector3(2, 2, 2)
                );
#else
            Geometry geodesatedBoxGeometry = new RenderStack.Geometry.Shapes.Cube(
                new Vector3(1.0f, 1.0f, 1.0f), new IVector3(6, 6, 6)
                );
#endif
            geodesatedBoxGeometry.Geodesate(0.75f);

            //  This is the best geo shape but somewhat slow to create
#if false
            Geometry subdividedIcosahedron = new RenderStack.Geometry.Shapes.Icosahedron(1.00);
            //subdividedIcosahedron = Sqrt3(subdividedIcosahedron);
            //subdividedIcosahedron = Mush(0.01f, subdividedIcosahedron);
            GeometryMesh sphereMesh2 = new GeometryMesh(
                subdividedIcosahedron,
                NormalStyle.PolygonNormals
                );
#endif

#if false
            GeometryMesh discMesh = new GeometryMesh(
                new RenderStack.Geometry.Shapes.Disc(1.0, 0.8, 32, 2),
                NormalStyle.PolygonNormals
                );
            GeometryMesh triangleMesh = new GeometryMesh(
                new RenderStack.Geometry.Shapes.Triangle(0.8f / 0.57735027f),
                NormalStyle.PolygonNormals
                );
#endif


            GeometryMesh sphereMesh = new GeometryMesh(
                //new RenderStack.Geometry.Shapes.Sphere(0.75, 24, 14),
                geodesatedBoxGeometry,
                NormalStyle.CornerNormals
                );
#if false
#endif
            //Geometry cylinderGeometry = new RenderStack.Geometry.Shapes.Cylinder(-0.5f, 0.5f, 0.5f, 24);
#if OPENRL
            Geometry cylinderGeometry = new RenderStack.Geometry.Shapes.Cone(-0.5f, 0.5f, 0.5f, 0.5f, true, true, 5, 1);
#else
            Geometry cylinderGeometry = new RenderStack.Geometry.Shapes.Cone(-0.5f, 0.5f, 0.5f, 0.5f, true, true, 24, 1);
#endif
            cylinderGeometry.Transform(
                Matrix4.CreateRotation(
                    RenderStack.Math.Conversions.DegreesToRadians(90.0f),
                    Vector3.UnitZ
                    )
                );
            //cylinderGeometry = Mush(0.08f, cylinderGeometry);

            GeometryMesh cylinderMesh = new GeometryMesh(cylinderGeometry, NormalStyle.CornerNormals);
#if OPENRL
            Geometry coneGeometry = new RenderStack.Geometry.Shapes.Cone(-1.0f / 3.0f, 2.0f / 3.0f, 0.75f, 0.0f, true, false, 5, 5);
#else
            Geometry coneGeometry = new RenderStack.Geometry.Shapes.Cone(-1.0f / 3.0f, 2.0f / 3.0f, 0.75f, 0.0f, true, false, 24 * subdiv, 10 * subdiv);
#endif
            coneGeometry.Transform(
                Matrix4.CreateRotation(
                    RenderStack.Math.Conversions.DegreesToRadians(90.0f),
                    Vector3.UnitZ
                    )
                );
            //coneGeometry = Mush(0.08f, coneGeometry);
            GeometryMesh coneMesh = new GeometryMesh(coneGeometry, NormalStyle.CornerNormals);

            /*  Physics shapes  */
            Shape cubeShape     = new BoxShape(1.0f, 1.0f, 1.0f);
            Shape sphereShape   = new SphereShape(0.75f);
            Shape cylinderShape = new CylinderShape(1.0f, 0.5f);
            Shape coneShape     = new ConeShape(1.0f, 0.75f);

            /*  Models  */
            float gap = 2.5f;

            //var defaultPng = materialManager.Texture("res/images/default.png", true);

            Material pearl = materialManager["pearl"];
            Material gold  = materialManager["gold"];
            //Material red        = materialManager.MakeTextured("red", defaultPng);
            Material red = materialManager["red"];
            //Material green      = materialManager["green"]  ;
            Material transparent = materialManager["transparent"];
            Material cyan        = materialManager["cyan"];
            Material blue        = materialManager["blue"];
            Material magenta     = materialManager["magenta"];
            Material pink        = materialManager["pink"];
            Material hsv         = materialManager["HSVColorFill"];
            Material hsv2        = materialManager["HSVColorFill2"];
            for (int z = 0; z < 1; ++z)
            {
                float Z = (float)(1 - z) * gap;
                AddModel(new Model("cube", cubeMesh, z == 0 ? pearl   : pearl, -2.5f * gap, 0.5f, Z), cubeShape);
                AddModel(new Model("box", cubeMesh, z == 0 ? gold    : pearl, -1.5f * gap, 0.5f, Z), cubeShape);
                AddModel(new Model("sphere", sphereMesh, z == 0 ? red     : pearl, -0.5f * gap, 0.75f, Z), sphereShape);
                AddModel(new Model("cylinder", cylinderMesh, z == 0 ? cyan    : pearl, 0.5f * gap, 0.5f, Z), cylinderShape);
                AddModel(new Model("cylinder", cylinderMesh, z == 0 ? blue    : pearl, 1.5f * gap, 0.5f, Z), cylinderShape);
                AddModel(new Model("cone", coneMesh, z == 0 ? magenta : pearl, 2.5f * gap, 1.0f / 3.0f, Z), coneShape);
                AddModel(new Model("cone", coneMesh, z == 0 ? pink    : pearl, 3.5f * gap, 1.0f / 3.0f, Z), coneShape);
                //AddModel(new Model("disc",     discMesh,     hsv,      4.5f * gap, 2.0f, Z), null);
                //AddModel(new Model("triangle", triangleMesh, hsv2,     4.5f * gap, 2.0f, Z), null);
                //AddModel(new Model("sphere",   sphereMesh2,  gold,    -0.5f * gap, 0.75f, Z), sphereShape);
                //AddModel(new Model("sphere",   sphereMesh,   transparent,   -0.5f * gap, 0.75f, Z), sphereShape);
            }

            AddCameras();
            AddCameraUserControls();

#if false
            if (RenderStack.Graphics.Configuration.useOpenRL)
            {
                var rl = Services.Get <OpenRLRenderer>();
                rl.BuildScene(renderGroup);
            }
#endif
        }
        public void UpdateFixedStep()
        {
            TranslateX.Update();
            TranslateY.Update();
            TranslateZ.Update();
            RotateX.Update();
            RotateY.Update();
            RotateZ.Update();
            SpeedModifier.Update();

            float speed = 1.0f + speedModifier.CurrentValue;

            if (TranslateX.CurrentValue != 0.0f)
            {
                /*  Right axis is column 0  */
                positionInParent += headingMatrix.GetColumn3(0) * TranslateX.CurrentValue * speed;
            }
            if (TranslateY.CurrentValue != 0.0f)
            {
                /*  Up axis is column 1  */
                positionInParent += headingMatrix.GetColumn3(1) * TranslateY.CurrentValue * speed;
            }
            if (translateZ.CurrentValue != 0.0f)
            {
                /*  View axis is column 2  */
                positionInParent += headingMatrix.GetColumn3(2) * TranslateZ.CurrentValue * speed;
            }
            if (
                (RotateX.CurrentValue != 0.0f) ||
                (RotateY.CurrentValue != 0.0f)
                )
            {
                heading   += RotateY.CurrentValue;
                elevation += RotateX.CurrentValue;
                Matrix4 elevationMatrix = Matrix4.CreateRotation(elevation, Vector3.UnitX);
                headingMatrix  = Matrix4.CreateRotation(heading, Vector3.UnitY);
                rotationMatrix = headingMatrix * elevationMatrix;
            }

            if (frame == null)
            {
                return;
            }

            Matrix4 localToParent = rotationMatrix;
            Matrix4 parentToLocal;

            Matrix4.Transpose(localToParent, out parentToLocal);

            // HACK
            if (positionInParent.Y < 0.03f)
            {
                positionInParent.Y = 0.03f;
            }

            /*  Put translation to column 3  */
            localToParent._03 = positionInParent.X;
            localToParent._13 = positionInParent.Y;
            localToParent._23 = positionInParent.Z;
            localToParent._33 = 1.0f;

            /*  Put inverse translation to column 3 */
            parentToLocal._03 = parentToLocal._00 * -positionInParent.X + parentToLocal._01 * -positionInParent.Y + parentToLocal._02 * -positionInParent.Z;
            parentToLocal._13 = parentToLocal._10 * -positionInParent.X + parentToLocal._11 * -positionInParent.Y + parentToLocal._12 * -positionInParent.Z;
            parentToLocal._23 = parentToLocal._20 * -positionInParent.X + parentToLocal._21 * -positionInParent.Y + parentToLocal._22 * -positionInParent.Z;
            parentToLocal._33 = 1.0f;

            Frame.LocalToParent.Set(localToParent, parentToLocal);
        }