예제 #1
0
 public void SynchronizeReadOnly(Graphics.GraphicsDevice context)
 {
     if (needReadOnlySynchronization)
     {
         throw new NotImplementedException();
     }
 }
예제 #2
0
            public SliderModelWrapper(SliderConstraintDesc desc, Pivot pivot, Graphics.GraphicsDevice graphicsDevice)
                : base(pivot, graphicsDevice)
            {
                var sphere = GetSphere(graphicsDevice).ToMeshDraw();
                var pipe   = GetCylinder(graphicsDevice).ToMeshDraw();
                var tip    = GetCone(graphicsDevice).ToMeshDraw();

                lastLowerAngularLimit = -desc.Limit.LowerAngularLimit;
                lastUpperAngularLimit = desc.Limit.UpperAngularLimit;
                var limitLower = GetLimitDisc(graphicsDevice, lastLowerAngularLimit).ToMeshDraw();
                var limitUpper = GetLimitDisc(graphicsDevice, lastUpperAngularLimit).ToMeshDraw();
                var material   = GetMaterial(graphicsDevice, pivot == Pivot.A ? OrangeUniformColor : PurpleUniformColor);
                var material2  = GetMaterial(graphicsDevice, pivot == Pivot.A ? OrangeNegUniformColor : PurpleNegUniformColor);

                limitMaterial = GetMaterial(graphicsDevice, LimitColor);

                AddModelEntity("Center", sphere, material);

                var xRotation = Quaternion.RotationZ(-MathUtil.PiOverTwo); // Yup rotated towards X

                AddModelEntity("X", pipe, material, xRotation);
                AddModelEntity("Xend", tip, material, position: CylinderLength / 2f * Vector3.UnitX, rotation: xRotation);

                var zRotation = Quaternion.RotationX(MathUtil.PiOverTwo); // Yup rotated towards Z

                AddModelEntity("Zend", tip, material2, position: CylinderRadius * 4f *Vector3.UnitZ, rotation: zRotation);

                lowerAngulerLimit = AddModelEntity("LowerAngularLimit", limitLower, limitMaterial, Quaternion.RotationZ(-MathUtil.PiOverTwo) * Quaternion.RotationX(-MathUtil.PiOverTwo)).Get <ModelComponent>();
                upperAngularLimit = AddModelEntity("UpperAngularLimit", limitUpper, limitMaterial, Quaternion.RotationZ(MathUtil.PiOverTwo) * Quaternion.RotationX(MathUtil.PiOverTwo)).Get <ModelComponent>();

                lowerLinearLimit = AddModelEntity("LowerLinearLimit", sphere, limitMaterial);
                upperLinearLimit = AddModelEntity("UpperLinearLimit", sphere, limitMaterial);

                Update(desc);
            }
예제 #3
0
            public ConeModelWrapper(ConeTwistConstraintDesc desc, Pivot pivot, Graphics.GraphicsDevice graphicsDevice)
                : base(pivot, graphicsDevice)
            {
                var sphere = GetSphere(graphicsDevice).ToMeshDraw();
                var pipe   = GetCylinder(graphicsDevice).ToMeshDraw();
                var tip    = GetCone(graphicsDevice).ToMeshDraw();

                lastLimitZ = desc.Limit.SetLimit ? desc.Limit.SwingSpanZ : MathF.PI;
                lastLimitY = desc.Limit.SetLimit ? desc.Limit.SwingSpanY : MathF.PI;
                lastLimitT = desc.Limit.SetLimit ? 2 * desc.Limit.TwistSpan : 2 * MathF.PI;
                var limitZ    = GetLimitDisc(graphicsDevice, lastLimitZ).ToMeshDraw();
                var limitY    = GetLimitDisc(graphicsDevice, lastLimitY).ToMeshDraw();
                var limitT    = GetLimitDisc(graphicsDevice, lastLimitT).ToMeshDraw();
                var material  = GetMaterial(graphicsDevice, pivot == Pivot.A ? OrangeUniformColor : PurpleUniformColor);
                var material2 = GetMaterial(graphicsDevice, pivot == Pivot.A ? OrangeNegUniformColor : PurpleNegUniformColor);

                limitMaterial = GetMaterial(graphicsDevice, LimitColor);

                AddModelEntity("Center", sphere, material);

                var xRotation = Quaternion.RotationAxis(Vector3.UnitZ, -MathUtil.PiOverTwo); // Yup rotated towards X

                AddModelEntity("X", pipe, material, xRotation);
                AddModelEntity("Xend", tip, material, position: CylinderLength / 2f * Vector3.UnitX, rotation: xRotation);

                var zRotation = Quaternion.RotationAxis(Vector3.UnitX, MathUtil.PiOverTwo); // Yup rotated towards Z

                AddModelEntity("Zend", tip, material2, position: CylinderRadius * 4f *Vector3.UnitZ, rotation: zRotation);

                this.limitZ = AddModelEntity("LimitZ", limitZ, limitMaterial, Quaternion.RotationY(MathF.PI + (lastLimitZ / 2f)), position: new Vector3(CylinderLength / 2, 0, 0)).Get <ModelComponent>();
                this.limitY = AddModelEntity("LimitY", limitY, limitMaterial, Quaternion.RotationY(MathF.PI + (lastLimitY / 2f)) * Quaternion.RotationX(-MathUtil.PiOverTwo), position: new Vector3(CylinderLength / 2, 0, 0)).Get <ModelComponent>();
                this.limitT = AddModelEntity("LimitT", limitT, limitMaterial, Quaternion.RotationZ(MathUtil.PiOverTwo) * Quaternion.RotationX(MathUtil.PiOverTwo - lastLimitT / 2f)).Get <ModelComponent>();

                Update(desc);
            }
예제 #4
0
            public PointModelWrapper(Point2PointConstraintDesc desc, Pivot pivot, Graphics.GraphicsDevice graphicsDevice)
                : base(pivot, graphicsDevice)
            {
                var sphere   = GetSphere(graphicsDevice).ToMeshDraw();
                var material = GetMaterial(graphicsDevice, pivot == Pivot.A ? OrangeUniformColor : PurpleUniformColor);

                AddModelEntity("Center", sphere, material);
            }
예제 #5
0
 public void Render(float time, Graphics.GraphicsDevice dev)
 {
     dev.SetActiveMaterial(mat);
     dev.SetVertexBuffer(vb);
     dev.SetIndexBuffer(ib);
     dev.Draw(DrawMode.Lines);
     dev.SetActiveMaterial(null);
     dev.SetVertexBuffer(null);
     dev.SetIndexBuffer(null);
 }
예제 #6
0
        private static GeometricPrimitive GetCylinder(Graphics.GraphicsDevice device)
        {
            if (!CylinderCache.TryGetValue(device, out var cylinder))
            {
                cylinder = GeometricPrimitive.Cylinder.New(device, CylinderLength, CylinderRadius, Tessellation);
                CylinderCache.Add(device, cylinder);
            }

            return(cylinder);
        }
예제 #7
0
        private static GeometricPrimitive GetCone(Graphics.GraphicsDevice device)
        {
            if (!ConeCache.TryGetValue(device, out var cone))
            {
                cone = GeometricPrimitive.Cone.New(device, AxisConeRadius, AxisConeHeight, Tessellation);
                ConeCache.Add(device, cone);
            }

            return(cone);
        }
예제 #8
0
        private static GeometricPrimitive GetSphere(Graphics.GraphicsDevice device)
        {
            if (!SphereCache.TryGetValue(device, out var sphere))
            {
                sphere = GeometricPrimitive.Sphere.New(device, CenterSphereRadius, Tessellation);
                SphereCache.Add(device, sphere);
            }

            return(sphere);
        }
예제 #9
0
 public void Render(float time, Graphics.GraphicsDevice dev)
 {
     if (mat != null)
     {
         dev.SetActiveMaterial(mat);
     }
     dev.SetVertexBuffer(vb);
     foreach (var block in blocks)
     {
         RenderBlock(block, dev);
     }
     dev.SetVertexBuffer(null);
     dev.SetIndexBuffer(null);
 }
예제 #10
0
        internal virtual void InternalRender(float time, Graphics.GraphicsDevice dev)
        {
            dev.ModelviewMatrix = owner.camera_mat * absolute_transform;
            var r = this as IRenderable;

            if (r.GraphicsInvalidated)
            {
                r.InitializeGraphics();
                r.GraphicsInvalidated = false;
            }
            if (r != null && r.GraphicsInitialized)
            {
                r.Render(time, dev);
            }
        }
예제 #11
0
        private static GeometricPrimitive GetLimitDisc(Graphics.GraphicsDevice device, float angle)
        {
            if (!LimitDiscCache.TryGetValue(device, out var cache))
            {
                cache = new Dictionary <float, GeometricPrimitive>();
                LimitDiscCache.Add(device, cache);
            }

            if (!cache.TryGetValue(angle, out var disc))
            {
                disc = GeometricPrimitive.Disc.New(device, LimitDiscRadius, angle, Tessellation);
                cache.Add(angle, disc);
            }

            return(disc);
        }
예제 #12
0
            public GearModelWrapper(GearConstraintDesc desc, Pivot pivot, Graphics.GraphicsDevice graphicsDevice)
                : base(pivot, graphicsDevice)
            {
                var pipe         = GetCylinder(graphicsDevice).ToMeshDraw();
                var tip          = GetCone(graphicsDevice).ToMeshDraw();
                var disc         = GetLimitDisc(graphicsDevice, 2 * MathF.PI).ToMeshDraw();
                var material     = GetMaterial(graphicsDevice, pivot == Pivot.A ? OrangeUniformColor : PurpleUniformColor);
                var discMaterial = GetMaterial(graphicsDevice, LimitColor);

                var xRotation = Quaternion.RotationZ(-MathUtil.PiOverTwo); // Yup rotated towards X

                AddModelEntity("X", pipe, material, xRotation);
                AddModelEntity("Xend", tip, material, position: CylinderLength / 2f * Vector3.UnitX, rotation: xRotation);

                AddModelEntity("Disc", disc, discMaterial, Quaternion.RotationZ(MathUtil.PiOverTwo)).Get <ModelComponent>();

                Update(desc);
            }
예제 #13
0
 public virtual void Render(float time, Graphics.GraphicsDevice dev)
 {
     if (model != null && mat != null)
     {
         if (mat != null)
         {
             dev.SetActiveMaterial(mat);
         }
         dev.SetVertexBuffer(model.VertexBuffer);
         foreach (var part in model.Parts)
         {
             dev.SetIndexBuffer(part.IndexBuffer);
             dev.Draw(Graphics.DrawMode.Triangles);
         }
         dev.SetIndexBuffer(null);
         dev.SetVertexBuffer(null);
         dev.SetActiveMaterial(null);
     }
 }
예제 #14
0
        private static Material GetMaterial(Graphics.GraphicsDevice device, Color color)
        {
            if (!MaterialCache.TryGetValue(device, out var cache))
            {
                cache = new Dictionary <Color, Material>();
                MaterialCache.Add(device, cache);
            }

            if (!cache.TryGetValue(color, out var material))
            {
                if (color.A == byte.MaxValue)
                {
                    material = GizmoEmissiveColorMaterial.Create(device, color, intensity: 0.85f);
                }
                else
                {
                    material = GizmoEmissiveColorMaterial.Create(device, color, intensity: 0.5f);
                }

                cache.Add(color, material);
            }

            return(material);
        }
예제 #15
0
            public static ModelWrapper Create(IConstraintDesc constraintDesc, Pivot pivot, Graphics.GraphicsDevice graphicsDevice)
            {
                switch (constraintDesc)
                {
                case Point2PointConstraintDesc p:
                    return(new PointModelWrapper(p, pivot, graphicsDevice));

                case HingeConstraintDesc h:
                    return(new HingeModelWrapper(h, pivot, graphicsDevice));

                case ConeTwistConstraintDesc ct:
                    return(new ConeModelWrapper(ct, pivot, graphicsDevice));

                case GearConstraintDesc g:
                    return(new GearModelWrapper(g, pivot, graphicsDevice));

                case SliderConstraintDesc s:
                    return(new SliderModelWrapper(s, pivot, graphicsDevice));
                }

                throw new NotSupportedException();
            }
예제 #16
0
 protected ModelWrapper(Pivot pivot, Graphics.GraphicsDevice graphicsDevice)
 {
     Pivot          = pivot;
     GraphicsDevice = graphicsDevice;
 }